Don't know what I'm doing wrong


#1

Her are my codes:
for (var 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);
}
}

please can you help me with a correct code and also show me what's wrong with mine?


#2

well, you first check if the number is dividable by 3 and then if it is dividable by 5, which means your code will never get to this line:

else if(i%3=== 0 && i%5 === 0){

because either this line:

if(i%3 === 0)

or this line:

else if(i%5 === 0)

has already ended the condition check, i suggest you change the order of your if statements