SyntaxError: Parser error


#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 <= 1)
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 win");
}
};
else if(choice1 === "scissors"); {
if(choice2 === "paper"); {
return ("Scissors win");
}
else {
return ("Rock wins");
}
};


#2

What error are you getting from your code?


#4

SyntaxError: Unexpected keyword 'else'


#5

That means there's an else that's in the wrong place (or you've misplaced braces).


#6

The trouble is in your "if" and "else if" statements.

When creating a conditional, you don't put a semi-colon after the condition.

You have:
if (choice1 === choice2); { ... }

It should be:
if (choice1 === choice2) { ... }

It looks like all of your conditions have this so you'll have to go back and remove all the semi-colons and try again.


#7

Thanks for the feedback, I ended up starting over and figured out where I messed up!


#8

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