Unexpected token else


#1


https://www.codecademy.com/courses/spencer-sandbox/0/3?curriculum_id=506324b3a7dffd00020bf661


My code keeps giving me the error message "SyntaxError: Unexpected token else". I can't figure out what's wrong!


var numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
    for(var i = 0; i < 21; i++) {
       
        if(i%3 === 0) {
            if (i%5 === 0) {
                console.log("FizzBuzz"); 
            };
            else {
                console.log("Fizz");
            };
        };
        else if(i%5 === 0) {
            console.log("Buzz");
        };
        else {
            console.log(i);
        };
    }


#2

Hello @digitaljumper81829,

You do not need to put semicolon after every closing curly brace. That is only required for functions and constructors. However, it IS good practice to put it after every line of code that doesn't indicate a code block or function ending. Clear out the inappropriate semicolons, and you'll be good to go :wink:!


#3

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