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


#1

I've been looking over my code for hours trying to figure out why I've been getting the error, for some reason I'm not seeing my wrong. Any help will be greatly appreciated.

---Code starts here---
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 "rock wins";
    }
    else {
        return "papers 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 "paper wins";
    }
}

};
compare(userChoice, computerChoice)


#2

Study this closely. See anything wrong?


#3

Honestly no :disappointed:


#4

Paper cannot win when choice1 is scissors. Scissors cut paper. Paper covers rock. Rock smashes scissors.

It's very common for learners to skip over the previous two else if statements and rush into this last case without studying the logic in the earlier patterns.

choice1 either wins or choice2 wins

else if (choice1 === "scissors") {
    if (choice2 === "paper") {
        return "scissors wins";
    } else {
        return "rock wins";
    }
}

#5

So basically, I've confused the coding by giving incorrect outputs.


#6

Yes, that is all that is awry in your code.


#7

Sorry for the late reply. I got it out, Thanks so much, I definitely let that pass over my head. :grin:


#8