Expected an Identifier and instead saw else


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661


Hi!
I am getting SyntaxError "Expected an Identifier and instead saw else" on the line where I've specified my second else/if statement.


ar 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 ==="scissors") {
    return "Scissors win";
    }
    }
else {
    return "Paper wins"
}
}


#2

we make an else if statement to check for choice1:

else if (){

}

then inside the else if we nest and if and else to check the possible options for choice2:

else if (){
    if(){
    
    } else {

    }
}

see how i nested the if and else? Now look at your code, see the difference?


#3

Is there possibly a bug? I am receiving the same syntax error as coursewhiz39390


#4

given coursewhiz39390 bug is in his code, this is very likely also what is causing your error. Please go here and make a new topic so you can get help


#5

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