What if choice1 is paper? Unexpected Token Else


#1

I keep getting a SyntaxError: Unexpected Token Else and iV'e been working on this for waaaaay too long so I'm out of options!

my code is

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

can someone please help! I have no idea what is holding me back!


#2

If you are using indentation you can easily detect, where am i wrong.
I styled to code like i would write it and added indentation to it. Can you spot the mistakes now?

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

#3

thankyou so much! I finally got it, I decided to actually write down physically the code and really space it out and it was due to the indentation that I missed a }!!!!