Not understanding syntax error


#1

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

Syntaxerror: unexpected token else


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

your else tag should be inside else if tag

 else if(choice1 === "rock") {
        
        if(choice2 === "scissors") {
            return "rock wins";
        }
    }  // here you closed else if  //remove it
        else {
            return "paper wins";
        }

      // you should close here  //add here }

read my comment .

same for the next


#3

type error:compare is not a function.
plzz help me out with this errors
http://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/1?curriculum_id=506324b3a7dffd00020bf661#


#4

I tried that but it is still giving me the same error. In the previous exercise, it wouldn't let me continue unless i closed off the function before the else statement.


#5

@cssplayer73235, could you post an updated version of your code?

@mkshyamsundar96, please make a new topic so we can help you, this topic is for helping cssplayer


#6

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

#7

else if(choice1 === "rock") {
        
        if(choice2 === "scissors") {
            return "rock wins";
        }
        else {
            return "paper wins";
        }
    // missing } to close else if
        else if(choice1 === "paper") {
            if(choice2 === "rock") {
                return "paper wins";
            }
        else {
            return "scissors wins";
        }
}; // unnecessary semi-colon 
// missing } to close your function

see the comments in the code above.


#8

Thank you very much for the help.


#9

#10

you should give credit to @rcodeman as well