3. and the good (IT WORKS BUT IM CONFUSED)


#1

https://www.codecademy.com/en/courses/spencer-sandbox/0/3

So basically it works but I'm not sure I understand why and I'm wondering if someone could explain. So when 3 is divided by 3 im sure that makes 1 (not 0). Yet as you can see in the code below it works only when x % 3 === 0. equally for example when x = 10 10 % 5 = 2, doesnt it??

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

#2

Hi the modulo % give the remain of the division
so if you do

10 % 3 it will remain 1
15 % 3 it will remain 0

#3

ahhh now i understand, thanks so much!


#4

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