Ruby isn’t limited to simple expressions of assignment like my_num = 100
; it can also do all the math you learned about in school.
There are six arithmetic operators we’re going to focus on:
Addition (+
)
Subtraction (-
)
Multiplication (*
)
Division (/
)
Exponentiation (**
)
Modulo (%
)
The only ones that probably look weird to you are exponentiation and modulo. Exponentiation raises one number (the base) to the power of the other (the exponent). For example, 2**3
is 8
, since 2**3
means “give me 2 * 2 * 2
“ (2 multiplied together 3 times). 3**2
is 9
(3 * 3), and so on.
Modulo returns the remainder of division. For example, 25 % 7
would be 4
, since 7 goes into 25 three times with 4 left over.
Instructions
Do a little math practice in the editor. When you’re ready, click Next.