Intro to Objects 1...And the good! - What are the === 0 for?


#1

...And the good!

Hello All,

I finished this exercise by adding the "===0". I had everything correct in my code, except I had to look at the forum to find that I was missing the "=== 0" for "i % 3" and "i % 5" etc.

I wish not to waste anyones time, but what is the purpose of "===0" parts?
What the heck is that all about?
I would have never figured that part out on my own.
Did I already complete an exercise in the past that explained this?
Where was the exercise?

Thanks ppl :slight_smile:

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

The ===0 is used to check if something is equal to zero, in this case "i % 3", "i % 5", etc.

Other languages would use ==0 to check if something equals zero but in javascript ===0 is preferred.


#3

Thank you for your reply boardsolver40102.

But why would we want to check if something is equal to zero? I would think that comparing if "i % 3" or "I % 5" would be enough. Now checking if they're equal to zero doesn't make sense to me, but I totally believe it's a way to solve such.


#4

The statement i % 3 doesn't check if i can be divided evenly by 3, it finds the remainder. So if you wanted to check if i is divisible by 3, you have to find the remainder first and then check if it is equal to zero.