Lesson 3: Wrong Number of Items


#1


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


Dont know what I did wrong...Can someone tell me what is wrong with it?


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 % 5 === 0 && i % 3 === 0) {
        console.log("FizzBuzz");
    } else {
    }   
};


#2

missing statement:

console.log(i);

Consider also the order of your if conditionals.


#3

okay that fixed the printing issue, but now it said I printed Fizz when I should have printed fizzbuzz, is that because of the order?

Thanks


#4

Yes, exactly. The compound condition should appear first, else it is never seen.


#5

ah never knew the order mattered. Is that a universal rule? Kind of confusing since the directions state the compound last in order


#7

I wouldn't call it a universal rule as much as a question of logic. Consider what happens when the test for 3 is first? If Fizz is printed, the compound condition is not seen because the if statement is finished. The same can be said of 5. Only when we first test the two combined does FizzBuzz get printed.


#8

Gotcha! That makes sense

Thank you. It worked now.


#10

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