'scissors' instead if 'undefined'


#1

HELP I NEED TO KNOW WHAT I DID WRONG.
Whenever i try to fix it nothing works I've tried for like an hour now.

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";
}
var compare = function(choice1, choice2) {
if(userChoice === computerChoice) {
return "The result is a tie!";

} else if(userChoice === "rock") {
    if(computerChoice === "scissors") {
        return "rock wins";
    } else {
        return "paper wins";
    }
} 
else if(userChoice === "paper") {
    if(computerChoice === "rock") {
        return "paper wins";
    } 
    else {
        return "scissors wins";
    }
} 
else {
    if(computerChoice === "rock") {
        return "rock wins"
    } 
    else {
        return "scissors wins"
    }
}

};
console.log(userChoice, computerChoice);


#2

Look at your function and the arguments there

var compare = function(choice1, choice2)

Here you can see two arguments choice1 and choice2.
But look in your if else statements, you dont work with these arguments.

Change that please


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.