Next steps (userChoice prompt)


So I'm trying to build my userChoice prompt so it gives an alert that the wrong choice was picked, and goes back to the prompt. So far, this is as far as I've got...

var userChoice = prompt("Do you choose rock, paper or scissors?");
if (userChoice !==

How can I select all three choices? How do I create an alert and then go back to the prompt?


ideally, use a loop, but those aren't covered yet.

You could use function for it, but its less ideal then loop


There is a more straightforward way to deal with this.

@beckerle80, just use logical operator || ('or') in your condition statement.


this is true if you use ==, for != (which i see in beckerle code) the and (&&) operator is required

which is how, i am curious, how?


Exactly! === is a great call :smiley:

var userChoice = prompt('rock, scissors or paper?');
if (userChoice === 'rock' || userChoice === 'scissors' || userChoice === 'paper') {
} else {
	var userChoice = prompt("told you to pick from rock, scissors or paper. Let\'s try once again");


That's what I was looking for! I wasn't sure if I could simply separate them by comma.


the problem with powell solution is, what if the user enters input wrongly 3 or 4 times? You need function or loop


Yeah, I got a syntax error :confused:


That is true.

However, nothing is wrong with a 'brutal force' solution when solving a problem. You can always optimize and check for edge cases later (you'd better :slight_smile: ).


Cool. Makes you think :slight_smile:


return can only be used inside functions, there is no function


I used console.log and it worked!


but as discussed, this will only catch faulty input once, not multiply times


Yeah, after I input incorrectly again it just runs and stops :confused:


ideally, you would use a loop, which hasn't been covered yet, or you will have to use functions


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