Division and Mod operations

The purpose of this page is to help you understand how computers do math. These exercises are not meant to help you understand math better, it is to teach you how to tell computer to do math for you.

Division and Mod

While you're probably already comfortable with division, this might be your first encounter with the modulo operation. The modulo operation is used to find the remainder after division. In JavaScript the modulo operator is denoted with a percent sign %.

A quick example - dividing 10 by 6:

  • Since 6 goes into 10 once, 10 / 6 gives us 1 and a remainder of 4
  • The modulo operation, 10 % 6 gives us that remainder of 4

Division

  1. How to turn 16849 into 168
Answer

Divide 16849 by 100 (you get 168.49)

Take the result, remove the decimal with Math.floor(168.49) (you get 168)

  1. How to turn 16849 into 1684
Answer

Divide 16849 by 10 (you get 1684.9)

Take the result, remove the decimal with Math.floor(1684.9) (you get 1684)

  1. How to turn 248 into 24
Answer

Divide 248 by 10 (you get 24.8)

Take the result, remove the decimal (you get 24)

  1. How to turn 168 into 16
Answer

Divide 168 by 10 (you get 16.8)

Take the result, remove the decimal (you get 16)

Mod

  1. How to get 49 from 25249
Answer

25249 % 100 gives you the last 2 numbers, 49)

  1. How to get 249 from 25249
Answer

25249 % 1000 gives you the last 3 numbers, 249)

Exercises

  1. How to get 24 from 25249
Answer

Get 249 from 25249 (look at mod section)

Get 24 from 249 (look at division section)

or

Get 2524 from 25249 (divide by 10)

2524 % 100, then remove decimal to get 24

  1. How to get 52 from 25249
Answer

Get 5249 from 25249

Get 52 from 5249

Edit this page on Github