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


#1


https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/0/4?curriculum_id=506324b3a7dffd00020bf661#


Congratulations, you've finished this section!

0.734819140451217
rock


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

if (computerChoice) {
    Math.random(0-0.33)
    console.log("rock");
    
} else if (computerChoice) {
    Math.random(0.34-0.66) 
    console.log("paper");
    
} else {
    Math.random(0.67-1)
    console.log("scissors");
};


#2

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:


#3

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


#4

My mind is blown.

:open_mouth:

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


#5

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?


#6

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


#7

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.


#8

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