Rock, Paper, Scissors: what is wrong with my code?


An error message says, "Oops, try again. There was a problem with your syntax." What's the problem? How can I fix it?

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice <= 0.33) {
    computerChoice = "rock";
} else if (computer choice <= 0.66) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";


check your variable used in your seconds if statement


Can someone please help me figure out whats wrong. I've been re-writing the code for literally 3 hours! I keep getting an syntax error for "unexpected token else"

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"


There should be a hint after the instructions about syntax for an if/else statement inside of an else if statement. It goes like this:

else if(condition){
if (condition){
return code;
} else {
return other code;

The first and last curly braces encapsulate the codeblock for the else if on line 1.


Thanks so much I didn't realize I was missing another set of {}


Thanks! I can't believe I made such a silly mistake.


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