What if choice 1 is scissors


#1

seems I'm not the best at this, a bit stuck on this

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

clearly I'm missing something, any ideas?

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

To call a function, you write the name of the function, followed by its arguments (if it takes them). The arguments go inside of parentheses. Like so:

function(argument1, argument2);


#3

so isn't this the function in question?
'var compare = function(userChoice, computerChoice)'


#4

It is the code for what you want the function to do before you ask it to do work by calling it.

Let's make up a function called funk.

var funk = function(){
console.log("we want the funk");
};

That won't do anything unless I call it:

funk();


#5

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