3. ...And the good! Whe 0 and not True?


#1

Just interested in why we do i&'any number' === 0? I thought it would be === true?

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

So for instance, why wouldn't this work:

if((i%3 === true) && (i%5 === true)) {
        console.log("FizzBuzz")
    }

I feel we are saying, If i is divisible by 5 and that is true, log this into the console. I feel like i divisible by 5 === 0 means it's false? Just looking for some clarification on this if possible.

Thanks everyone.


#2

% isn't isn't "divisibility test", but you can use its result to determine divisibility.


#3

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