What if choice1 is scissors?


#1

When I hit Save & Submit, it says: Oops, try again.
Make sure to call your compare function with userChoice and computerChoice as the arguments!
Where is the fault?
The code I wrote is:

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

Thank you.


#2

you didn't make a function call, when you have a function:

var testFunction = function(){
   return "call to execute";
}

then, after the function add the function call:

console.log(testFunction());

in wrapped the function call in a console.log, so that what gets returned, gets actually logged to the console. When you call the compare function, keep in mind the function arguments you need to supply to the function


#3

I do make a function:
var compare = function(userChoice,computerChoice) {
But it says:Make sure to call your compare function with userChoice and computerChoice as the arguments!


#4

Paste in your updated code


#5

but creating a function and calling the function are two different things, like i demonstrated in my previous answer. Otherwise, revisit exercise about function