Correct code but getting error


#1

Here is my code:
for (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);
}
}

it keeps saying you printed Fizz when you have printed FizzBuzz can you spot the error for me.

2.. I also want to ask instead of using i%3 === 0 can one just say i%3 and continues knowing that that means if I%3 evaluates to true then the condition follows.


#2

here is your code corrected

Edit:

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

or you can shorten it to this

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

#3

you code gives me error as well. It says: seems like you printed out the wrong numbers


#4

@lawreneagles i have made an edit to my initial post