"Your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and rock"


#1

i have been going over this for nearly an hour, however i do not understand what i am doing wrong?

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

#2
else if (choice1 = "paper"){

= is the assignment operator and not a comparison so you don't check if choice1 is paper but you make choice1 become paper. Which leads to the problem this case is always chosen because it has a value of "paper" and non-empty strings are treated as true:
http://www.sitepoint.com/javascript-truthy-falsy/
This applys for your scissors case as well, but as it is the last one here it is not that relevant although you should still change it.


#3

i made these adjustments, including the scissors case.

i now get "Your code returned 'scissors wins' instead of 'undefined' when the inputs are scissors and rock"


#4

Ok that's weird I can get the correct result running this code:

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

compare("scissors","rock");

which is basically your code copy&pasted with fixed equal signs and an additional } to close the function.