8. What if choice1 is "scissors"


#1

/*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 userChoice = prompt("Do you choose rock, paper, or scissors?");
var computerChoice = Math.random()
console.log(computerChoice)
if ( 0 < computerChoice < 0.33 ){
computerChoice = "rock";
} else if ( 0.34 < computerChoice < 0.66 ){
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
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";
}
}
}

"Oops, try again. Make sure to call your compare function with userChoice and computerChoice as the arguments!"
Please Help! I don't know what I'm doing wrong.


#2

You were to define your function with the arguments choice1 and choice2

but then call them with your prompts userChoice and computerChoice,
.

console.log(compare(userChoice, computerChoice))


#3

I tried that, Now it is telling me I have a problem with my syntax...


#4

I figured it out. Thank you.


#5

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