Introduction to Objects I ...And the good!


#1

I keep getting this wrong, im so bad at this Javascript, but i got help before but when i fixed my lines of code, it didnt seem that it still would work functionally.

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

What it prints out:

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

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


#2

Hi your for loop

for (var i = 0; i < 21; i++)

you should print number from 1-20 so your i should be equal to 1 like that

for (var i = 1; i < 21; i++)

#3

Hi projectalioskar,

You're very close - the problem is that you've placed an if rather than an else if on line 6.

This means your conditional statement has split into two:

if (i % 3 === 0) {
    console.log("Fizz");
} else if (i % 5 === 0) {
    console.log("Buzz");

and

if (i % 3 === 0 && i % 5 === 0) {
    console.log("FizzBuzz");
} else {
    console.log(i);
}

Also, don't forget to place semicolons at the end of your statements (e.g. console.log("Fizz"); )

P.S. Format your code when you post it into the Q&A forums - it makes it much easier for others to read :slightly_smiling: