7/9 Syntax Error Unexpected Token


#1



Problem with Syntax

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(choice 1 === "paper")
{
if(choice2 === "rock")
{
return "paper wins";
}
else
{
return "scissors wins";
}
};

please help I have been stuck on this for so long, can't figure out what I did wrong


#2

missing the " before scissors


#3

thank you. is there another mistakes though because that was just a typo when i posted this code....ugh I still can't figure out the problem.


#4

Yeah,

Three other mistakes:

  1. choice 1 = remove the space

missing the opening curly bracket
3. missing closing bracket for else if before the next else if..


Remember the syntax:

if (condition) {
  // do something
}
else if (condition) {
  if (condition) {
    // do something 
  } 
  else {
    // do something else
  }
}

#5

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