Not printing FizzBuzz


#1



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

HI try to read that discussion you'll find out why it doesn't work


#3

simple fix, the way that its reading the code is from top to bottom. It checks the "if" statemeant on line 3 first. reverse the order and put the else if(i % 3 === 0 && i % 5 === 0){
console.log("FizzBuzz"); statemeant on line 3 with "if"

for(i = 1; i <= 20; 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);}
}


#4

gotcha :slight_smile: . Thank you