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


#1

So here's the deal I get the error message Your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and rock but the inputs weren't scissors and rock to begin with, the right inputs are different, the one for the computer is correctly dispalyed in the console and the other one i input it so i know what it is but it gives me this error, no matter the inputs. , the thing is the program works correctly and if i read the console and if I input paper and the computer has rock I will win and so on, the logic works and the output in the console is correct but it says it's expecting undefined instead , any help ?

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

compare(userChoice, computerChoice)

#2

Hi, in your last else if statement inside it you put if (choice2 === "paper") instead of
if (choice2 === "rock") so you should change the return statement and the else statement so its sould be like that

  else if (choice1 === "scissors") {

        if (choice2 === "rock") {
            return "rock wins";
        }

        else {
            return "scissors wins";
        }
    }
};

compare(userChoice, computerChoice


#3

Thanks! Solved the issue!