I got through the rock paper scissors expercise though the response does not match the value!



Congratulations, you've finished this section!


var userChoice = prompt ("Do you choose rock, paper or scissors?");
var computerChoice = Math.random()

if (computerChoice) {
} else if (computerChoice) {
} else {


Hey in your if and else if parentheses you need to compare the value of computerChoice with another value.

For example:

if (computerChoice) {

Should look like

if (computerChoice <= 0.33) {

Now the random value that is assigned to computerChoice will be tested. If it is less than or equal to 0.33 the if block will run. If not it will move onto the else if.

} else if (computerChoice) {

Should therefore read as

} else if (computerChoice <= 0.66) {

So that covers two possible outcomes. Your else is fine because there's only one more possible output in this scenario and it has it covered.

Also I'm not sure if you intended to put the extra Math.random() methods in each of the three code blocks but these are not necessary as we already have computerChoice containing the result of that method.

Hope that clears things up :slight_smile:


thank you so much for the detailed explanation. really appreciate it!


My mind is blown.


I had no idea you could do that to Math.random().


Maybe I'm not understanding completely. But as far as I know rock is printed every time because any number other than 0 and -0 defaults to true in conditional logic?


I'm still fuzzy on the Math.random part.


Don't believe so, because it's not assignment to anything. Right?. For whatever reason though it seems you can put almost anything in the parentheses and it'll ignore it and create a random number regardless

Interesting stuff.


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