What if Choice1 is paper? Syntax Error:Unexpected token else


#1

Help please!

I've had a look at the forums and keep going back to my code (but I think I'm just confusing myself now). Here's my code below, can someone please tell me where I'm going wrong?

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


#2

There are to many curly brackets. (wrongly placed)

Try to get a better formatting.


#3

Can you now see where you have to correct?

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

#4

I'd like to say that I can but I can't!


#5

What formatting? Maybe use jsbeautifier.org and for the code do it step by step and only go on if every example works, works the way it should and works in a way that you understand. The way to write long and complex code is break it down to small and simple steps.