Problem with the end of Rock, Paper, Scissors


#1

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);

var compare = function(choice1, choice2){
if ( choice1 === choice2) {
return("The result is a tie!")
}
else if (choice1 = "rock"){

if(choice2 === "scissors"){
    return("scissors 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")
}

}
}

If i save and run this code i can execute it but in the end he says 'your computer returned "paper wins " instead of "undefined" when your input was rock and scissors.'

Can you explain me my failure?


#2

The lesson checker does not expect the final else if statement until the next lesson. Were it not present, the result would be undefined when choice1 is scissors.

Either comment out, or remove that last else if branch.

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

#3

Hi thanks for helping out! Unfortunately that didnt work out for me. :confused:


#4

Didn't notice earlier,

if (choice1 = "rock")

should be,

if (choice1 === "rock")

We use === when making comparisons. The = operator is for assignment operations, only.