...And the good!


#1

Error: You printed Fizz when you should have printed FizzBuzz

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

if (i % 3 === 0) {

console.log("Fizz");

} else if (i % 5 === 0) {

console.log("Buzz");

} else if ((i % 3 === 0) && (i % 5 === 0)) {

console.log("FizzBuzz");

} else {

console.log(i);

}
}


#2

This right here is your problem,

You should not put them in separate parentheses but have only one set of parentheses that stores your condition,

else if (i % 3 === 0 && i % 5 === 0) {


#3

Still have the same error, Thanks though.


#4

Also, get rid of this else statement,

And then turn this else if statement into an else statement with no conditions,

into,

else {
    console.log("FizzBuzz")
}

#5

I got it bandit, thanks agian :slight_smile: )

for (var 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);

}
}


#6

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