What If Choice1 is Paper?


#1



https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661#

Stuck here, keep getting Syntax Error: unexpected token else"
I wrote the code the same way as I did for choice1 === "rock" but its not working,
can anyone see the error?


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


#2

HI this part you forgot to close the else if statement wi th }

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

then here

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

you should add two } at the end.... one for closing the else if statement the other is for closing the compare function


#3

Thanks for the quick reply!

https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661#

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

I added those curly braces but I'm still getting "unexpected token else" I'm quite lost in it at this point.


#4

Now here you forgot to open the if statement

if(choice2 === "scissors") {#add this one
return "rock wins";
}

#5

Sweet Odin's Ravens. Thank you