Syntax error in "Rock, Paper, Scissors"


#1


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


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


#2

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


#3

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


#4

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


#5

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


#6

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.


#7

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


#8

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