9. NEXT STEP (looping untill the user types in the right choice)


#1

I am currently stuck on the task where the user gives a wrong answer "dog" instead of "rock, paper, scissors".
1). The user should be asked: "Do you choose rock, paper or scissors?"
2). If he gives a wrong answer, I want the prompt to show up untill the user types in the right answer.
So my codes are:
var userChoice = prompt("Do you choose rock, paper or scissors?");
//User gives a wrong answer!
var validateUserChoice = function(choice0) {
do {
userChoice = prompt("Please, choose either rock, paper or scissors!");
}
while (choice0 !== "rock" || choice0 !== "paper" || choice0 !== "scissors");
};

It stops right after the first line. How can I make it repeat untill I get from the user either rock, paper or scissors?
Anyone?


#2

@sayuribo take a look at this post to get an idea what to do


#3

Hi Sayuribo

I thought that this solution was the simplest and most effective. I added the below while loop between the function and my calling of the function to ensure that the game will continue to prompt for an entry in the event of ties or incorrect entries:

while(userChoice === computerChoice || (userChoice !== "rock" && userChoice !== "scissors" && userChoice !== "paper"))
{
userChoice = prompt("Do you choose rock, paper or scissors?");
computerChoice = Math.random();
compare(userChoice, computerChoice);
};

Hope that helps.

JF Arigho