...And The Good


#1

I almost got it. Please help a brother out. been staring at this screen for over an hour.


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


#2

for i=15, FizzBuzz should be logged. But the if condition (if 15 % 3 === 0 ) is true, so Fizz is logged instead, and the loop moves on to the next number


#3

I understand that. how do I make this code log FizzBuzz? I thought i % 3&& 5 ===0 would work, then i tried i % 3 || 5 === 0, still didnt work. Then, I tried i % 3===0 && i % 5 === 0, still didnt work. Then I tried i % 3 ===0 || i % 5===0, still didnt work. what am I not seeing.


#4

i % 3===0 && i % 5 === 0 is the right condition, but its never reached. Because for i=15, if evaluates to true, so the else if and else conditions aren't evaluated (this only happens then conditions before evaluate to false) and the loop moves on to the next numbers

So you will need to change the order in which you if a number is fizzbuzz, fizz or buzz


#6

thank you. it works now


#7