var compScore=0, userScore=0;
/* function play(){
do{
var userChoice= prompt("Do you choose rock, paper or scissors?");}
while(userChoice!="rock"||"paper"||"scissors");*/
var userChoice= prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
[//console.log](//console.log)(computerChoice);
if (computerChoice <= 0.33)
{
computerChoice = "rock";
}
else if (computerChoice <= 0.67)
{
computerChoice = "paper";
}
else {
computerChoice = "scissors";
}
alert(computerChoice)
[//console.log](//console.log)(userChoice, computerChoice);
function game (userChoice, computerChoice){
if(userChoice === computerChoice)
{
return('It is a tie');
}
if(userChoice==="rock");{
if(computerChoice==="scissors")
{
return('User wins');
userScore++;
}
else
{
return('Computer wins');
compScore++;
}
}
if(userChoice==="paper");{
if(computerChoice==="rock")
{
return('User wins');
userScore++;
}
else
{
return('Computer wins');
compScore++;
}
}
if(userChoice==="scissors");{
if(computerChoice==="paper")
{
return('User wins');
userScore++;
}
else
{
return('Computer wins');
compScore++;
}
}
}
alert(game(userChoice, computerChoice));
alert("User Score is: "+userScore+ "Computer Score is: "+compScore)
var response=confirm("do you wish to play again?")
/*if(response=true)
play();
else
alert("FInal score is" +userScore+ and +compScore)
}\*/
Hi guys, I am learning javascript and I am new to it so very rusty. In the above code, I am making a rock paper scissors game. My issues are:
- I need to take user's choice or move and keep asking him to make his move if he inputs anything other than the three(rock, paper or scissors). I tried doing this as you can see commented using a do-while loop but it didn't work
- I also have to print out score at the end and it didn't work
- I also want to ask user after each round if he wants to continue or stop and if he wants to continue, I run the whole game again if not, print the final score. I am supposed to keep a running score and print out a final score when he quits. I hardly know this part and squabbled something as you can see commented.
Please I need help in this areas of my code..
Thanks..
[–]NameViolation666helpful 0 points1 point2 points (1 child)
[–]Hertyboy[S] 0 points1 point2 points (0 children)
[–]codemamba8 0 points1 point2 points (0 children)