Rock, paper, scissors what if choice1 is paper?


#1

it keeps coming up with a "unexpected token else" warning and i don't understand how to solve it. pls help.
var compare = function (choice1, choice2) {
if (choice1 === choice2) {
return ("The result is a tie!")
}
else 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

you shouldn't have the semi colon at the end of the code. Also, check to make sure it isn't a bracket error by making sure all open brackets have a corresponding closing bracket and vice versa


#3

The semicolon at the end is actually fine. The problem is this else if case:

else if (choice2 === "scissors") {
        return ("Rock wins")
    }
    else {
        return ("Paper wins")
    }

compare it to your second one:

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

which is actually correct apart from the unnecessary () around your return statements.


#4

thank u! that actually worked