4/9 Why doesn't this work?


#1

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

if (computerChoice <= 0.33){
computerChoice = "rock";
}
else if (computerChoice >= 0.34 && computerChoice <= 0.66){
computerChoice = "paper";
}
else (computerChoice >= 0.67 && computerChoice <= 1);{
computerChoice = "scissors";
}
console.log(computerChoice);
console.log(userChoice);

I don't understand! Why does my console only say "Scissors" when I run the code???


#2

Hi @lauri0202,

If it may help please see the code example below. In short you were subject to the syntax gremlins a little. The else statement needs a little work, first it does not perform any conditional checks, and we need to remove the semi-colon at the end, and hopefully the rest will give you an idea of what it should look like and you're good to go coding.

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

if (computerChoice <= 0.33){
    computerChoice = "rock";
}
else if (computerChoice >= 0.34 && computerChoice <= 0.66){
    computerChoice = "paper";
}
else { //remove this entire snippet - (computerChoice >= 0.67 && computerChoice <= 1);{
    computerChoice = "scissors";
}
console.log(computerChoice);
console.log(userChoice);