FizzBuzz!


#1

It's printing FizzBuzz at 0 (weird, and printing 21. Getting the error message "
Oops, try again. It looks like you printed out the wrong number of items."


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

FizzBuzz!
1
2
Fizz
4
Buzz
6
7
8
Fizz
10
11
Fizz
13
14
FizzBuzz!
16
17
Fizz
19
Buzz
21


#2

I think you need to change i = 0 to i=1 because you don't need to start from 0 you need to start from 1, also you should delete all the i++ after each if/else functions i think they are unnecessary.


#3

This is the updated code, but it's still giving me: "Oops, try again. It looks like you printed out the wrong number of items."

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

#5

FizzBuzz should not be a function, The lesson checker is not looking for one, but code that runs straight away.

This should be in an else clause so it only prints when nothing else does.


#7

Thanks, that worked!


#8