Syntax error in "Rock, Paper, Scissors"


I'm confused about what I've done wrong. It looks like all of the results are correct, but I keep getting this error message: "Oops, try again. Your code returned 'rock wins' instead of 'scissors wins' when the inputs are paper and scissors"

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


Error message seems pretty straight-forward, what's confusing about it?


Well, I'm confused about what I should fix.


The equals sign "=" is used for assigning values. 3 equals signs side by side "===" are a comparison operator.


Oh. Wow, I can't believe I didn't notice that now that you've pointed it out. Thanks!


You can tell from the error message which return statement was reached. How did it get there? Which conditions were evaluated and what results did they get? Which results should they have gotten? Which one(s) behaved incorrectly? That's what you should fix.


I guess I'm just not familiar enough with coding and error messages yet. Thanks!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.