Reputation: 1
trying to get to grips with javaScript and come across syntax missing error however it doesn't say what is missing it is just blank?
"Error= SyntaxError: Missing before statement"
any help is appreaciated!
Code below:
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 === "paper") {
return "scissors wins";
}
else {
return "rock wins":
}
};
}
"
Upvotes: -1
Views: 56
Reputation: 3192
Change:
return "rock wins":
to:
return "rock wins";
(i.e. use a semi-colon rather than a colon to end the statement)
Upvotes: 2
Reputation: 150080
I'm not sure why the error message you get is worded like that, but the error is on this line:
return "rock wins":
You've got a colon where you should have a semicolon.
Fix that and the code runs. (In Chrome, the error I get is about the colon being an unexpected token.)
Upvotes: 2