What if choice1 is paper? SyntaxError: Unexpected token else


#1



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


I cannot seem to figure out the problem with my code. I've been looking for a correct answer to the problem, but all the other codes looks the same as mine yet it's still not correct. Maybe it's something little I'm not seeing

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";
        }
    }
};


#2

Hi first you should remove the ; after the closing } of the first else if statement

    else if (choice1 === "rock") {
        if (choice2 === "scissors") {
            return "rock wins";
        }
        else {
            return "paper wins";
        }
    }; <== this one

then here

if choice2 === "rock" {
            return "paper wins";
        }

you shoudl put choice2 === "rock" between ()


#3

I am also getting the "unexpected token else" and I can't figure out where I've gone wrong here.

/*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";
        }
    }
}

#4

I have the same problem...


#5

Hi this part you forgot to close your else if statement

else if (choice1 === "rock") {
        if (choice2 === "scissors") {
            return "rock wins";
        }
        else {
            return "paper wins";
    }
} < == one here

#6

Ooooh, of course it was a bracket! Too many brackets XD
Thanks a ton!


#7

HI can you post your code?