Incorrect number of items in list - fizzbuzz


#1

indent preformatted text by 4 spacesvar fizzBuzz = function() {

for (var i = 1;i <= 20;i++) {
    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);
    }
}

};

console.log(fizzBuzz());

I get everything right with the above code but after printing out:indent preformatted text by 4 spaces
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
undefined

The undefined is making it throw this "
Oops, try again. It looks like you printed out the wrong number of items."


3...And the Good:: Missing after for-loop initializer!
#2

You are already logging each step from within the function. What happens if you take the console.log on the function call away?


#3

undefined is what JavaScript responds with when there is no return value from a function and the program ends on exiting it. It is not anything your code caused.

However, the SCT doesn't know to call your function, so it sees nothing. Move the code out of a function and onto the global namespace to run on Submit without a function call.