Syntax problem: unexpected Else


#1

Can someone please help me...I can't figure out what is wrong

It keeps saying that I have "unexpected token else"

var compare = function (choice1, choice2) {
    if (choice1 === choice2) {
        return "The result is a tie!";
}

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

#2

This code block for your else if statement is the wrong syntax, you are missing a condition for choice1 and a nested if statement.

Look at your else if statement for (choice1==="paper").

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

That's almost 100% correct. You just need to remove the semicolon after your else if condition.

If I were you, I would study the 2nd else if code block. Look at where the braces go. See where the if statement starts and ends. Do the same for the else statement. Look at where the braces are. Then go back and make alterations to your first else if statement.


#3

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