You printed Fizzbuzz, should've printed Fizzbuzz


#1


Oops, try again.
You printed Fizzbuzz when you should have printed FizzBuzz

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);
    }  
}

Anyone? Thanks


#2

Probably a typo, change Fizzbuzz to FizzBuzz (Capital B)


#3

Ahhhhh.... D'oh. Thanks a lot


#4

For more consistent code, it is generally better to avoid magic number 21, such as:

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

this way it is more consistent that we are getting number 1 to 20.


#5

why is that? are you saying that sometimes it might give you 1-21?


#6

Yes, you must write 1-21,
and
3% and 5% it's nesting

if (i % 3 === 0 || i % 5 === 0) {
        if (i % 3=== 0 ) {
            if (i % 5=== 0 ) {
              console.log("FizzBuzz");
            }
            else{
              console.log("Fizz");
            }
        }
        else{
            console.log("Buzz");
        }
    }
   else{
        console.log(i);
    }