...And the good! - Why error occurs?


#1

I type like below...

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

and output is...

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

I think both code and output are correct but it appear error message like:

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

Why???


#2

Hi , its missing the else statement on your code.
And This console.log(i); should be inside the else statement


#3

Thanks! wizmarco!

I misread the instructions.
My code was successfully compiled!