Expected an identifier and instead saw "else". Missing ";" before statement


#1

I keep getting this notification by my "else if (choice1==="scissors")

I got this for every step, What exactly does this alert even mean and why do I need a semicolon before the statement (Which I dont even know what the statement it's referring to). I've also cross referenced other people's codes that have done this project too. I dont get it....

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

#2

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

Your else part should be inside the else if.


#3

else if checks what choice1 is, you do this right for rock and scissors, but for papers your else (which means computer won) is not nested inside your else if


#4

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