8. What if Choice1 is Scissors - Error makes no sense


#1

I get the error "Oops, try again. Your code returned 'The result is a tie!' instead of 'undefined' when the inputs are scissors and rock" when ever I input rock, paper, or scissors. But if I don't answer the prompt and hit okay it passes the lesson? Any ideas?

UPDATE: FIGURED IT OUT. I FORGOT TO CALL THE FUNCTION

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

#2

how did you call the function?


#3

console.log("text here" + " " + userChoice);
console.log("text here" + " " + computerChoice);
compare(userChoice. computerChoice);


#4

Why did you use userChoice and computerChoice instead of choice2 and choice2 from the brackets inside the function?


#5

Because choice1 and choice2 are the parameters for the function. Not the variables that are called.


#6

Yes choice1 and choice2 are the parameters of the function and that is the reason why you should use them inside of your function and not userChoice and computerChoice. Currently you're using the global variables userChoice and computerChoice and the parameters (choice1 and choice2) as well as the arguments (the userChoice and computerChoice used here):

compare(userChoice. computerChoice);

are not in use. The idea is that by using userChoice and computerChoice in your function call you assign those values to your parameters and therefore you can use the parameters inside of your function as if they have that values.