Has anyone figured out how to ask the player for a new choice and have the game run again with the player's new input?


#1


Has anyone figured out how to ask the player for a new choice and have the game run again with the player's new input? Do I use some sort of loop? also, how do I make it so that the user's response isn't case sensitive so that, "ROCK", "Rock", and "rock" all work when comparing. I've tried: if (Choice1 === "rock", "Rock", "ROCK");

Copying and pasting doesn't work on the code for some reason. I'm running Mac OS Sierra if it's a compatibility issue. but yeah!


#2

you could use a do while loop:

do {
   userChoice = prompt("choice rock paper or scissors").toLowerCase();
} while (userChoice != "rock" && userChoice != "paper" && userChoice != "scissors");

this also solves your other problem, toLowerCase() will make the input of the user lowercase, problem solved. I know, this uses code not covered yet. You could also use functions instead, but it is not as nice


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.