What if choice 1 is paper?Unexpected token else


#1

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

SyntaxError: Unexpected token else

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


#2

Please, post all your code because this part seems to be correct.


#3

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

#4

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";
        }
}
} // here you closed your compare() function

// so, this else is unexpected
else if(choice1 === "rock") {
     if(choice2 === "scissors") {
    return "rock wins";
    }
             else {
                 return "paper wins";
             } 
     }

Please, review your compare() function.


#5

Thank you! It works now...


#6

It's great but your second else-if statement has the same condition as the first.

Inside this else if statement, write an if / else statement. If choice2 === "rock", return "paper wins". Else, return "scissors wins".

So, should be

else if(choice1 === "paper"){
   // your code block
}

Please, review your code block inside the second condition.


#7

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