What if choice1 is scissors?


#1

var userChoice = prompt("Do you choose rock, paper or scissors?");

console.log("user: + " " + userCoice);
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 wins";
}
else
return "rock wins";
}
}
};
compare(userChoice,computerChoice);


#2

what is wrong with dis code?


#3

You tell us. What are we looking for?


#4

it says Oops, try again. There was a problem with your syntax.


#5

I want it to work. I cant see the problem


#6

There's quite a bit of code to look through, make sure you've got a back-up copy and then start removing parts of your code. When you stop getting a syntax error, then you know that the problem is in what you removed and you can focus on that part.


#7

You're missing an opening curly bracket { after else.


#8

else if (choice1 === "scissors") {
if (choice2 === "rock") {
return "rock wins"; }
else {
return "scissors wins"; /* Not "rock wins" */
}
}
};
compare(userChoice, computerChoice)