What's wrong with my code? (Lesson: What If Choice 1 is "paper"?)


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
I’m getting a “SyntaxError: Unexpected keyword ‘else’” Can’t seem to find what’s wrong with my syntax? Please help! Thanks!

```

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

<do not remove the three backticks above>

#2

else between two else if

here is:

else {
    return "paper wins";
}

i think this code is better

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

#3

Thanks so much! That worked!


#4

and this is may be better, becaues if choice1 equal by “scissors” there is no act.

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

the previous code is improve in owner(not developed) but this code is develop for get better result.
mods can close and mark as solved topic.

good job