3. And the good


#1

I keep getting the message that I printed out the wrong number of items but after looking around on this forum as far as I can see what I've written is exactly the same as the correct solution! Would really appreciate some help with this, here's my code:

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

#2

Ignore that, I realized I was doing the for loop wrong! However now I've got this code and it's printing fizz instead of fizzbuzz for 15:

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

#3

for i=15, the if condition is true, so fizz is logged to the console, once if is true, else if and else don't run, the loop goes to next number


#4

That's what I thought might be happening, but I've looked at other peoples' code and it seems to work fine!

However I now changed the order and it works, thanks!


#5