FizzBuzz


#1

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

I am only able to print out "FizzBuzz" and am getting a "You printed 3 when you should have printed Fizz" message


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


#2

You first check if i is divisible by both 3 and 5, and if that's the case you check if i is divisible by 3 or 5. But that's already clear from i beeing divisible by 3 and 5.

Hope this helps you solving it, if not tell us.


#3

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