What if choice1 === “scissors”?


#1

I'm still stuck, keep getting syntax error:
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(choice1, choice2) {
if (choice1 === choice2) {
return "The result is a tie";
}
else if (choice1 === "rock") {
if (choice2 === "scissors") {
return "rock wins";
}
else {
return "paper wins";
}
}
else if (choice1 === "paper") {
if (choice2 === "rock") {
return "paper wins";
}
else {
return "scissors wins";
}
}
}
else if (choice1 === "scissors") {
if (choice2 === "rock") {
return "rock wins";
}
else {
return "scissors wins";
}
}
};

Instructions:
Under your old code, use the same structure as the past two exercises and finish off your function.
02. 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.
03. Call your function and pass in userChoice and computerChoice as your two arguments.
04. Press Save & Submit Code and your game should work! Congratulations!
Lastly, what if choice1 is "scissors"? Given choice1 is "scissors",

a. if choice2 === "rock", then "rock" wins.
b. if choice2 === "paper", then "scissors" wins.


#2

Perfect syntax! Now study your other else if statements and see if you notice something different. All the braces have an effect, just like all semicolons and all parentheses will.


#3

thank you ill try that


#4

still don't work, help


#5

Can you post your latest code?


#6

else if (choice1 === "paper") {
if (choice2 === "rock") {
return "paper wins";
}
else {
return "scissors wins";
}
}
} // you already closed the function here.you should not do that.so remove it.

now

else {
return "scissors wins";
}
}
};
here after this you need to call the function.without calling the function will not work.
do you know how to call the function?


#7

its ok i've got it now but thanks for helping [:grin:]


#8

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