You printed "Fizz" when you should've printed "FizzBuzz"


#1


for (var i = 1; i < 21; i++) {
    if (i % 3 === 0) {
        console.log("Fizz");
    } else if (i % 5 === 0) {
        console.log("Buzz");
    } else if (i % 3 === 0 && i % 5 === 0) {
        console.log("FizzBuzz");
    } else {
        console.log(i);
    }
}

What is wrong with my code? I saw someone on here who put the exact same thing, but in a different order. Is the order that important? If so, why? And why wasn't that presented to me in the instructions? I just typed out the code in the order I saw each instruction?


#2

The order is important, once a if/else if condition is evaluated to , that block is executed, the rest of the else if/else are skipped, and the loop starts its next iteration


#3

You're absolutely right. That makes total sense. Perhaps I missed the lesson where the order was important or just self explanatory and I'm incompetent.


#4