SyntaxError: Unexpected token else


#1


Hi folks,
I'm new here, stuck on an exercise all day, I'm sure I'm missing some small detail...
Thanks in advance.


7 What if choice1 is paper?


I get the message:
SyntaxError: Unexpected token else


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

This error indicates a problem with brace placement in most instances. Check that everything is properly opened and closed. The nesting above is a little bit off.


#3

Thanks, got it worked out. My brain and eyes just needed to get away fromit for a day.


#4

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