...And the good! STUCK


#1

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

Hi,
Can't seem to be printing numbers that can be divided by 3 or 5.
Could someone enlighten me please?
Thanks so much in advance.

var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]; 

for(i=1; i<numbers.length; 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);
    }
}

#2

for i=15, you want to print fizzbuzz

but when i=15, the if condition (15%3 == 0) evaluates to true, Fizz is printed, the loop moves on to the next number

checking of a number is fizzbuzz, should be your first order of operation


#3

Thx you help me a lot too, havent thought that when program finds x % 3 === 0 and satisfies the condition it wont go further


#4

This helped me too.:slight_smile:


#6

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