What if choice1 is paper? Need to know what I'm doing wrong


#1

I have been stuck on this for awhile and I can't figure out for the life of me what I've done wrong. Here is my code as is:

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

As-is it says that I have an unexpected token else, and previously it had kept throwing an unexpected token { as an error.


#2

Hi,

here is the fix:

else if (choice1 === "rock") {
        if (choice2 === "scissors") {
               return "rock wins"; 
        } else {
            return "paper wins";
        }
// here i miss a } to close the else if

#3

Hi, thanks for responding. Please explain this a little further...I'm not seeing what the original problem was. Thank you! :smile:


#4

If you open a { you should close it :smile:

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";
                 }
       // here you didnt close your else if } and opend a next one
       else if (choice1 === "paper") {
                if (choice2 === "rock") {
                    return "paper wins";
                } else {
                    return "scissors wins";
                }
       }
}