Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPrateek Pamecha
2,482 PointsEqual to 0 means its completely divisible. "%" operator returns the remainder when a dividend is divided by divisor. For example:
10 (dividend) % 3 (Divisor) will return 1 as Remainder. This is because
10 (dividend) = 3(Divisor) * 3 (Quotient) + 1 (Remainder)
So if a number is not completely divisible then "%" operator will return some value as there will be something in remainder.
Example of Completely Divisible
10 (dividend) % 2 (Divisor) will return 0 as Remainder. This is because
10 (dividend) = 2 (Divisor) * 5 (Quotient) + 0 (Remainder)
I hope this answers why we check for is equal to 0 for checking if number is completely divisible.
Joshua Blair
2,064 PointsJoshua Blair
2,064 Points% is for displaying remainders. So if something perfectly divides into another it should return 0.
4 divided by 2 = 2 ( 4 % 2 = 0 ) 5 divided by 2 = 2 with 1 remainder ( 5 % 2 = 1 )