Next steps (userChoice prompt)


#1

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?


#2

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

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


#3

There is a more straightforward way to deal with this.

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


#4

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?


#5

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

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

#6

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


#7

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


#8

Yeah, I got a syntax error :confused:


#9

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: ).


#10

Cool. Makes you think :slight_smile:


#11

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


#12

I used console.log and it worked!


#13

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


#14

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


#15

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


#16

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