If, else if, else. Where is the mistake?


#1


#2

The problem is in our elif statement. Please post your code so I can help you understand what the problem is.


#3

The code that I wrote is literally this one:

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

var computerChoice = Math.random();

console.log(computerChoice)

if (computerChoice < 0.33) {

console.log("rock")

}
else if (computerChoice <= 0.66 ) {

console.log("paper")

}
else (computerChoice > 0.67) {

console.log("scissors")

}


#4

:slight_smile:

These statements are incorrect because you are not trying to print out values but assign them so what you would do is,

computerChoice = "rock"

and so on...

And also,

Print out computerChoice after all the if and else statements.


#5

Brilliant! Thank you so much for everything!

I owe you one.


#6

You're super welcome :grin:

If that was the answer you were looking for feel free to click the solution button below my reply. :slight_smile:


#7

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