...And the good!


#1


https://www.codecademy.com/courses/spencer-sandbox/0/3?curriculum_id=506324b3a7dffd00020bf661#


It's supposed to log "Fizz" if the number is divisible by 3, and Buzz if it's divisible by 5. If it's divisible by 3 and 5 it should print "FizzBuzz"; it says it's printing "Fizz" instead of "FizzBuzz".


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&&i%5==0){console.log("FizzBuzz")}
 else{console.log(i)}   
}


#2

Hi @johncdf,

Shift the condition if( i%3 === 0 && i%5===0) {console.log("FizzBuzz")} to become the first condition to be checked, the code run from top down.

You need the code to check this condition first rather than ( i%3 === 0), that is why it's printing "Fizz" first.


#3

Ah, I see what I did wrong. Thanks alot, man!


#4

You're welcome. :slight_smile:


#6

This topic is solved.