Understading the IF / ELSE IF / ELSE


#1


I am not stuck on anything I just want to understand why during the if statements the code cannot look something simliar
like this

IF (computerChoice <= 0.33) ~ rock
ELSE IF (computerChoice <=0.66) ~ paper
ELSE (ComputerChoice <= 1) ~ scissors


I tried to narrow what the the limitation was for the random Math, but I don't understand why it would come up with
a syntax error instead of undefined number


Replace this line with your code. 
var userChoice =prompt ("Do you choose rock, paper, or scissors?");
var computerChoice= Math.random();
console.log (computerChoice);

if(computerChoice <=0.33) {
    computerChoice = "rock"; 
    } else if (computerchoice<= 0.66 ) {
    computerChoice = "paper";
    } else {
    computerChoice= "scissors";
}


#3

Just to put a close on this question...

else does not take a conditonal expression. It is the default branch.

if (condition) {}
else if (other_condition) {}
else {}

Be sure to add check spelling to your debugging check list.


#4

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