Rock Paper Scissors Syntax Error


#1

I am not sure where the mistake is.

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


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

#2

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


#3

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