What if choice1 is paper - unexpected token else


#1


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


I am getting the error message "unexpected token else." Running through JSlint I can see the error is isolated to "else if (choice1 === "paper")." I've tried so many small things that I'm sure my code is comically butchered at this point and I am stuck. Thank you for your help.

Edit: I see now that code from part 6 was not imported to 7 for some reason. Solved. Nevermind. Thanks everyone.

var compare = function(choice1, choice2) {
    if (choice1 === choice2) {
    return ("The result is a tie!");
    }
    
    else 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 this.part You closed The else if statement before and its missing The choice1 Like your second if statement

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

#3

You are correct. It took me an embarrassing amount of time to realize my code from section 6 wasn't transferred to section 7. I edited my post upon discovery of that. Thank you.


#4

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