7/9 Syntax Error: unexpected token else. Need help with this


#1



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


This code always gives me the error in the title.


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(userChoice +" " + 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"; } 
};


Help! What if choice1 is paper?
#2

You have problems on the position of your curly brackets. See position of curly brackets below for your reference.

    var compare = function() {
        if () {
            return "";
        }
        else if () {
            if (){
                return "";
                }
            else { 
                return "";
                }
        }
        else if (){
            if () { 
                return ""; 
                }
             else { 
                return ""; 
                } 
        }
    };

Hope this helps.


#3

This is an error. Compare it to your own code for if (choice2 === "rock") and see the difference.


#4

Thank you! i missed a curly bracket to close the first else if statement.


#5

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