SyntaxError: Unexpected token else -I can not understand where the error


#1

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";}
}
};


#2

It would seem you have 6 } but only 5 { try deleting one } or adding one { to your code and see if that helps any!


#3

var compare = function(choice1, choice2) {
   if("choice1 === choice2") { // syntax errors: "choice1" === "choice2"
      return "The result is a tie!";
   }
};  // here you closed the function
   else if("choice1 === rock") {
      if ("choice2 === scissors") {
         return "rock wins";
      } else {
         return "paper wins";
      }
   }
};

I formatted your code. So, now you can see your errors.


#4

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