...And the good!


#1

I don't know where is my mistake. Please solve it.

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

I really appreciate your reply. Thanks


#2

Should this be, i%5?


#3

It doesn't need to be in a function
i%8 should be changed to i%5
you should change i <= 21 to i <= 20 since it includes the 20. if you just use the < then it would be i < 21

My completed code.
for (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)
}
}