3. and the good!


#1



Replace this line with your code.

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

}

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


#2

} else {
console.log("Fizz");

#4

console.log("Fizz"); is belong to the block of if(i%3==0)
:confounded:

and I execute the code and get right output.

my logic:

Whether the if(i%5==0) satisfy, it already satisfy if(i%3==0).
so, i think console.log("Fizz"); will dispay.


#5

The logic in the OP is sound, save that missing else { in the nested if.

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

Also, it is a best practice to use strict type matching comparisons with === to avoid type mismatches from occuring unnoticed.