What if choice1 is scissors?


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/4?curriculum_id=506324b3a7dffd00020bf661#


My code only works if the result is a tie, else it will say: ReferenceError: Can't find variable: choise1 (or choise2 depending on the outcome). Please help! What am I doing wrong??


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 (choise2 === "scissors") {
            return "rock wins";
        }
        
        else {
            return "paper wins";   
        }
    }
    else if (choise1 ==="paper") {
        
        if (choise2 === "rock") {
            return "paper wins";   
        }
        else {
            return "scissors wins";   
        }
    }
    else if (choise1 === "scissors") {
        if (choise2 === "paper") {
            return "scissors wins";   
        }
        else {
            return "rock wins";   
        }
    }
};
compare(userChoice,computerChoice);


#2

spelling error, supposed to be choice
Check you have this spelling error multiple times in your code


#3

Jesus Christ.. Have been looking at this for the last 30 minutes! Wow.. Really did that spelling error a lot of times! Thank you so much!


#4

2 posts were split to a new topic: What if choice1 is scissors?


What if choice1 is scissors?
#5