Reputation: 3
Please i need help with the code below. I have been getting this error message SyntaxError: expected expression, got keyword 'if' and I think I'm doing the right thing.
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
`enter code here`
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!";
}
Upvotes: 0
Views: 55
Reputation: 31920
Content of functions in Javascript goes inside braces. So your current code
var compare = function(choice1, choice2)
if (choice1 === choice2) {
return "The result is a tie!";
}
will become
var compare = function(choice1, choice2)
{
if (choice1 === choice2) {
return "The result is a tie!";
}
}
Upvotes: 1