FizzBuzz


#1

Hello,

I'm having a little problem getting past this exercise (3..And the good FizzBuzz). I'm getting the error:

Oops, try again. It looks like you printed out the wrong number of items.

where did I go wrong? I also tried to add the number (i's value) before the Fizz, Buzz or FizzBuzz (ie console.log(i + " FizzBuzz") ) Please review my code below.
Thanks in advance for your help
Exercise Instructions

Print out the numbers from 1 - 20.

The rules:
For numbers divisible by 3, print out "Fizz".
For numbers divisible by 5, print out "Buzz".
For numbers divisible by both 3 and 5, print out "FizzBuzz" in the console.
Otherwise, just print out the number.

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

Output 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz


#2

Remove this bit of code. It is the reason you are printing too many numbers.


#3

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