Lesson 3: Wrong Number of Items



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) {
    } else if(i % 5 === 0) { 
    } else if(i % 5 === 0 && i % 3 === 0) {
    } else {


missing statement:


Consider also the order of your if conditionals.


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?



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


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


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.


Gotcha! That makes sense

Thank you. It worked now.


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