Part 8 Error Message: Call your compare function


#1


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

Receiving error message: "Oops, try again. Make sure to call your compare function with userChoice and computerChoice as the arguments!"

When I leave the arguments as "choice1, choice2" I do not receive any errors, but when I replace with userChoice, computerChoice, I receive the above message. Very confusing.

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


#2

When you're writing a function, the input that goes in the parentheses is called the parameter.

Example of function declaration

var funkshun= function(parameter){
return parameter * 2;
}

Then when you call the function to do something, the parameter is called an argument.

Example of function being called

funkshun(3);

So for this exercise, they want you to call your compare function and pass in userChoice and computerChoice as the arguments. Before doing so, go back into your compare function declaration and change the parameters back to choice1 and choice2.


#3

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