Why This Matters
Multiplication is a shortcut for repeated addition. Instead of writing 5 + 5 + 5 + 5, you write 5 x 4 = 20. This shortcut is not just convenient -- it is essential. Algorithms that multiply run in constant time, while the equivalent repeated addition takes linear time. The difference becomes enormous at scale.
Division is the inverse of multiplication. It asks: how many equal groups can you make? 20 divided by 5 is 4, because you can split 20 items into 4 groups of 5. But what happens when things do not divide evenly? That is where the remainder appears. 17 divided by 5 gives a quotient of 3 with a remainder of 2, because 5 x 3 = 15 and 17 - 15 = 2.
The remainder operation (modulo) is one of the most useful tools in programming. It cycles array indices, detects even and odd numbers, implements hash functions, and powers cryptographic algorithms. Mastering multiplication, division, and remainders gives you tools you will use in every program you write.
Define Terms
Visual Model
The full process at a glance. Click Start tour to walk through each step.
Multiplication builds a grid (area model). Division partitions into groups, producing a quotient and remainder.
Code Example
// Multiplication
console.log(6 * 7); // 42
console.log(-3 * 4); // -12
console.log(-2 * -5); // 10 (negative times negative = positive)
// Division
console.log(20 / 4); // 5
console.log(17 / 5); // 3.4 (JavaScript gives decimal result)
// Integer division (floor)
console.log(Math.floor(17 / 5)); // 3 (quotient)
// Remainder (modulo)
console.log(17 % 5); // 2
console.log(10 % 2); // 0 (even number)
console.log(11 % 2); // 1 (odd number)
// The division relationship: dividend = quotient * divisor + remainder
const dividend = 17;
const divisor = 5;
const quotient = Math.floor(dividend / divisor);
const remainder = dividend % divisor;
console.log(`${dividend} = ${quotient} * ${divisor} + ${remainder}`);
// 17 = 3 * 5 + 2
// Practical: cycling through array indices
const colors = ["red", "green", "blue"];
for (let i = 0; i < 7; i++) {
console.log(colors[i % colors.length]);
}
// red, green, blue, red, green, blue, redInteractive Experiment
Try these exercises:
- Verify that multiplication is commutative: pick two numbers and check that
a * b === b * a. Is division commutative? Try12 / 4vs4 / 12. - Use
%to extract the last digit of any number. What is12345 % 10? What about12345 % 100? - What is
0 % 5? What about5 % 0? Why does one work and the other cause an error? - Verify the division equation: for any dividend and divisor, check that
dividend === quotient * divisor + remainder. - Use modulo to determine if the numbers 100, 101, 102, 103 are even or odd.
Quick Quiz
Coding Challenge
Write a function called `longDivision` that takes two positive integers: a dividend and a divisor. Return a string in the format 'quotient R remainder'. For example, longDivision(17, 5) should return '3 R 2'. Do NOT use the division (/) or modulo (%) operators. Instead, use repeated subtraction to find the quotient and remainder.
Real-World Usage
Multiplication and division are the backbone of countless computations:
- Scaling and resizing: Image editors multiply pixel dimensions by a scale factor. Doubling an image size means multiplying width and height by 2.
- Unit conversion: Miles to kilometers, Fahrenheit to Celsius, bytes to megabytes. Every conversion uses multiplication or division by a conversion factor.
- Hash tables: The modulo operator maps keys to bucket indices.
hashCode % tableSizedistributes data across an array. - Clock arithmetic: 15:00 military time modulo 12 gives 3:00 PM. Modular arithmetic wraps values into a fixed range.
- Pagination: Dividing total items by page size gives the number of pages. The remainder tells you how many items are on the last page.