8. What if choice1 is scissors?


#1

Ok so these are the instructions:
Instructions
Under your old code, use the same structure as the past two exercises and finish off your function.
We need to use the variables userChoice and computerChoice. Uncomment the first lines of the code by deleting /* on line 1 and */ on line 9, the variables are now active and can be called.
Call your function and pass in userChoice and computerChoice as your two arguments.
Press Save & Submit Code and your game should work! Congratulations!

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

Whats 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(userChoice,computerChoice){
if(userChoice === computerChoice){
return "The result is a tie!";
}
else if (userChoice === "scissors") {
if (computerChoice === "rock") {
return "rock wins";
}
else {
return "scissors wins";
}
}
}


#2

These are parameters that should be arguments in the compare() function call. The parameters are supposed to be choice1 and choice2

To call your function,

compare(userChoice,computerChoice);

#3

ooo I see now...

Thanks! :slight_smile:


#4

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