Build "Rock, Paper, Scissors": What if choice1 is rock? 6/9 HELP


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/2?curriculum_id=506324b3a7dffd00020bf661


It says "SyntaxError: Unexpected token else" whenever I try to submit the code, I've been trying to debug it and see if I did anything wrong and I can't seem to see anything. Can anyone help me by telling me what I did wrong or paste in the right code?


/*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(choice === "scissors") {;
    return "rock wins";
};
else {;
    return "paper wins";
}; 
};


#2

Look carefully on your semicolons and curly brackets.

See reference below for your better understanding.

var compare = function() { // open curly bracket of your FUNCTION
        if () {  // open curly bracket of your IF
            return "";
        }   // close curly bracket of your IF
        else if () {   // open curly bracket of your ELSE IF
            if () {  // open curly bracket of your IF inside your ELSE IF
                return "";
            }  // close curly bracket of your IF inside your ELSE IF
            else {  // open curly bracket of your ELSE inside your ELSE IF
                return "";
            }  // close curly bracket of your ELSE inside your ELSE IF
        }  // close curly bracket of your ELSE IF
    };  // close curly bracket of your FUNCTION

Hope this helps


#3

Missing a closing quote.

Unnecessary semi-colon.

Many unnecessary semi-colons. There are others that I didn't point out.

Your code should look like this:
/*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);*/
prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
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");
}
}
}


#4

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