Help in "Next Steps"


#1

Is there something that can tell the computer that only if the user writes these specific words, will they go ahead. Like I tell the computer, "Only if he says rock, Rock, paper, Paper, scissors and Scissors can he/she go on to the next part."


#2

Yes.
You could make a question with precise requirements, just like any other prompt:

var userChoice = prompt("What's the code?");

Anything I fill in will be saved into userChoice. The correct code would be for example: 'rock, rock, paper, paper, scissors, scissors'. Then, you can see if I got the code correct, like so:

if(userChoice === "rock, rock, paper, paper, scissors, scissors") {
     //do something
}

That's telling the computer that if userChoice is EXACTLY 'rock, rock, paper, paper, scissors, scissors', it can proceed to the next thing it has to do.


#3

There's also the cool option to give a default answer for prompt by using

var userChoice = prompt("Please enter your choice?","rock, paper or scissors");

And for multiple conditions you can either use nested conditions or have a look at the glossary or google about && (logical AND) and || (logical OR) which let you chain conditions e.g.

A && B

where the statement A && B is true if both statements A and B are true and false otherwise.


#4

hey.
I know php basics a bit. There you have to use arrays for that purposes.
I'm new in JS but I do see that many things are similar in these languages. Probably you have to go further in studying JS to see if arrays are used here too.


#5

Yes using an array and a for in or even a for each loop might work as well, but at this point neither a loop nor an array are introduced so better keep it simple at this point.