Syntax error: unexpected token else


#1

Dont know what i am doing 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 ==="paper") {

if(choice2 === "paper") {
    return "paper wins"; }


else {
    return "scissors wins"; }

}

};


#2

is there a curly bracket missing from this part of the code?.....

var compare = function(choice1,choice2) {
if( choice1 === choice2) {
return "The result is a tie!";
}

var compare = function(choice1,choice2)
{
if( choice1 === choice2)
{
return "The result is a tie!";
}
}

struggled with this part myself yesterday...but hope that helps with resolving it


#3

Please, please, format your code.

You are not closing your first "else if".


#4

well spotted cssblaster, I could see there was a } closing bracket missing but was not sure exactly where - i hold my hand up I thought it was after the first if...


#5

That is why it's a good practice to use indentation and when posting the code to the discussion, then to use the post format. You can easily detect where it is missing then :relaxed:


#6

its a shame I don't know how to work the codeboard to open a blank console to enter the code and work on. I tried setting up a project so I could have a blank console window to test my code as I progress along with the lessons but as I am still in my first week I am not familiar enough with the provision to do that yet.