Something wrong with my code? Unexpected keyword else


#1

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

For some reason my code keeps saying unexpected keyword else. anyone know what's wrong?


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


#2

Brackets are usually the problem. We never write a semi-colon before else, and there is one missing at the end. Only the last brace should have a semi-colon. The first if is missing an opening brace, as well.


#3

Can you show me your code please? I think that'd help. Thanks


#4

var compare = function (args) {

    // function body code

 }; // semi-colon this line only

function body code

    if ( tie condition) {

    }
    else if ( rock condition ) {
        if ( paper condition ) {

        } else {

        }
    }

The above is pseudo code; the pattern is what is important.


#5

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