8) What if choice1 is scissors? 'Undefined' error?


I keep getting the following error: "Oops, try again. Your code returned 'scissor wins!' instead of 'undefined' when the inputs are scissors and paper"
The game works correctly whatever choice I input. I'm not sure why the code is supposed to be returning "undefined" and not the output values I specified...

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

console.log(compare(userChoice, computerChoice));


I'm getting the same issue and I've changed my choice1/2 to user/computer as instructed so that doesn't seem to be the issue. I'm wondering if this assignment is buggy cuz it seems that way to me.


instead of "console.log(compare(userChoice,computerChoice));"
it should just be compare(userChoice,computerChoice);


@boardjumper34824 Afaik the exercise is ok, but there are many reasons that can cause an error like this and for exercises this "short" it happens to be that they all look pretty similar so if you want help with your code please open your own topic and post your code and the error message your receive.

@marissa_defratti The first guess would be that you're missing an "s" here:

         else {
            return "scissor wins!"; //scissors instead of scissor

@f_adumo actually using console.log is fine the other one would just call the function and makes use of a console feature that echoes the last value, but console.log is more reliable for more outputs than the last value.