Syntax error unxepected token else


#1


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


syntax error unexpected token else
cant seem to figure it out
please help

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"

}
else if(choice1==="scissors") {
    if(choice2==="paper") {
        return "scissors wins"
    }}
else {
    return "rock wins"
}
}


#2

Look at my comment. Please post all of your code after making the necessary corrections to your last 2 else if statements. :slight_smile:


#3

Sorry about that, here is the full code. Should i remove both brackets or just one from the previous double brackets? thanks for your help!

var userChoice = prompt("Do you choose rock, paper or scissors?");
var compare = function(choice1, choice2){
if(choice1 === choice2){
return "The result is a tie!";
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"

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

};
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);


#4

Only one of the double curly brackets should be removed


#5

I meant to point out earlier that this is a perfect else if statement for you to model the rest of your else if statements on. Let's take a look at your posted compare function though:

Not trying to beat a dead horse but, use your 1st else if statement to make corrections in your 2nd and 3rd else ifs. Then close the compare function. Hope this helped.


#6

That helps a ton! thanks for the help


#7

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