...And the good!


#1


what is wrong with this code i can't seem to figure out the problem with the syntax

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

to declare a variable i:

var i

to also give it a value:

var i = "hello world"

maybe you should give i a value? like the number at which we need to start counting

if i is 15, the first condition we see is:

if (15 % 3 === 0)

which is true, Fizz is logged to the console, and we move on to the next number.

15 should log fizzbuzz to the console, so to check if i is fizzbuzz should be the first thing you do (since 15 is also divisively by 3 and/or 5, it will never get to fizzbuzz)


#4

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