3. FizzBuzz wrong number of items


#1


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


Hello,
My code seems to be working according to the instructions. However, I keep getting the following error message.

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

What am I not understanding about the instructions?

Thanks,

var num = 0;
var totalTimes = 20;

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


#2

How many item is the exercise expecting you to print out?


#3

It says to print out 1 - 20. If the number is divisible by 3 or 5 to print out either "fizz", "bizz", or "fizzbizz".

I have attached my output.

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


#4

So there are a couple things going wrong here. I will list them out.
Firstly your num needs to start at 1.
var num = 1;
There is no need to use i in your for, you should replace it with num.

for (num; num<=totalTimes; num++)

You need to put console.log(num); inside your else. As you want to console.log all the remaining numbers that were not turned into fizz/fizzbuzz.

But the rest of the code is great. :slight_smile:


#5

This num = num + 1; is also unnecessary.

Let me know if that worked.


#6

NO reason for the thrid else {} condition.

Note the previous advice and you should be fine.


#7

Solution, move:

console.log(num);

into your else statement.

Ignore all other suggestions.


#8

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