Lesson 7. if Choice1 = paper


#1


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


I'm getting this error message:

"Oops, try again. Your code returned 'paper wins' instead of 'scissors wins' when the inputs are paper and scissors "

can someone help me understand what I am doing wrong? I cant seem to follow the logic of the error message. And when I change my code to reflect what the message is telling me to correct it switches to saying "your code returned 'scissors wins' instead of 'paper 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

Your code should be a switch statement. Also it should be if(choice2 === "rock")


#3

Agreeing with @itschrisburton, the = sign is an assignment operator. You should use the === comparison operator for your if and else if conditions.


#4

Thanks! I really appreciate it


#5

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