SyntaxError: Unexpected token else


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

};

Not sure what is wrong here. I am on the second else if which I see as the same as the first. What is missing?


#2

    return "paper wins";
  }
//Missing closing bracket " } " here!
else if(choice1 === "paper"){

I hope this helps!


#3

Getting token } from that now


#4

Could you post your updated code for me?


#5
 return "paper wins";
}

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

}

};


#6

Oh sorry I see what happened, now there's an extra closing bracket at the end of your code!

} //Delete one of these!
} //Delete one of these!

};

#7

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

};

Unexpected end of input? Sorry!


#8

Ah see you deleted both of them, so add one of the closing brackets back :smiley: brackets are a programmers nightmare until you get the hang of them.

}
//Add one closing bracket here " } "
};

#9

we got there! Thanks!