Rock, Paper, Scissors Syntax Error


#1

Here's the code (Error is unexpected token else):

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
var compare = function (choice1,choice2) {
if (choice1 === choice2) {
return "The result is a tie!"
}
else if (choice1 === "rock") {
if (choice2 === "scissors") {
return "rock wins"
}
else {
return "paper wins"
}

else if (choice1 === "paper") {
 if (choice2 === "rock") {
  return "paper wins"   
 }
 else { 
     return "scissors wins"
 }
}
}

}


#2

take one of your } from the end of your code and put it at the very end of your first else if statement.

You need to make sure that all of your if's, else if's, and else's open and close independently.

Hope this helps


#3

Could You reply the fixed code? XD I don't realy understand what You said :smiley:


#4

Oh wait fixed it XD Thank you