8. Practice Makes Perfect - A question about the math


#1




https://www.codecademy.com/en/courses/ruby-beginner-en-ET4bU/1/4?curriculum_id=5059f8619189a5000201fbcb

I have a question about the math in this piece of code.

def by_three?(number)
    if number % 3 == 0
        return true
    else
        return false
    end
end


So that's saying if the number is divided by 3 and the remainder is exactly 0 then true, otherwise false. Wouldn't 0 be the only number that would return true then? For example 6 / 3 = 2. Isn't there a remainder in that? Sorry if my math is bad, I'm not terribly good at it. Thanks for the assistance.


#2

Remainder 0, so 6 is a multiple of 3.

  _____
3 ) 6 | 2  =>  6 / 3
  - 6
  _____
    0      =>  6 % 3

#3

I am embarrassed at my lack of understanding for basic math. I now understand what the code is doing. Thank you.


#4

The math module on Khan Academy begins at about 3rd grade level and goes all the way up to pre-college and beyond. It can take weeks or months to get through but is worth the time and effort.