Rock Paper Scissors Syntax Error


I am not sure where the mistake is.

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

if (computerChoice >= 0) 
   computerCoice = "rock";}
else if (computerChoice >= 0.34);
    computerChoice = "paper";}
else (computerChoice >= 0.68);
computerChoice = "scissors";}


you seem to have swapped. You get a value between 0 and 1 (0 and 1 not included)

So lets look at your first if condition:

if (computerChoice >= 0)

which is true for all values, you should only have the values of .33 and less to be rock

same for paper.

Also, for paper:

else if (computerChoice >= 0.34);

that semi-colon is very dangerous, it prevents the else if clause from running properly. Also, else can't have a condition, since it is everything else, remove the condition of your else statement


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