3... And the good


#1


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


Doesn't work as intended


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


#2

I did this and it seemed to work.
Can someone explain to me why the order/priority made a difference?

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


#3

well, once if condition is true, it moves on to next iteration/run of the loop, else if only runs when if condition is false

so for your first code, fizz is printed for i=15, while it should be fizzbuzz


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.