"Expected an identifier and instead saw 'else'"



At the last 'else if' statement, when you are supposed to make choice 1 === "paper", I get an error saying "Expected an identifier and instead saw 'else'" and "Missing ';' before statement". I sat here looking at my code for about 10 minutes, and have changed it numerous times to try to figure out what the problem is. I asterisked the line with the error below.

All help would be greatly appreciated!

var compare=function(choice1,choice2){
if(choice1 === choice2){
    return "The result is a tie!";
else if(choice1 === "rock");{
if(choice2 === "scissors"){
    return "rock wins";     }
    return "paper wins";    }
**else if(choice1 === "paper");{**
if(choice2 === "rock"){
    return "paper wins";    }
    return "scissors wins";}


We don't put semicolons after we finish header of if/else if,

like one of the place you did this is here..

else if(choice1 === "rock");

There is one more, check that refine/eliminate it.


Completely brainfarted! Thank you so much for pointing this out, I should've seen that XD


Keep checking/revising the syntax . They are key elements of our programs.


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