Where did my code go wrong?


#1

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";
}
}
};

It says syntax error: unexpected keyword 'else'? Can someone please help me figure this out.


#2

else may only follow if, so you've got something else in front of some else


#3

Can you please try to format your code? I cant even read the code you posted above. This will improve that..


#5

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";
        }
    }
};

#6

There it is, thank you for your assistance.. it is greatly appreciated.


#7

Here is the code, thanks :slightly_smiling:


#8

Like @ionatan said you cant have an else if statement and then another else if statement. It goes if,elseif, then else