Student-friendly HTML, CSS, and JavaScript reference with examples
Math.round(4.5) // 5Five operators do the math.
5 + 3 // 8 — add
5 - 3 // 2 — subtract
5 * 3 // 15 — multiply
5 / 3 // 1.666… — divide
5 % 3 // 2 — divide, but keep the remainder instead
% (modulus) is its own topic — that’s next up after this one.
Operators aren’t the whole story. A handful of Math methods cover the rest of what
you’ll reach for constantly.
Math.round(4.5) // 5 — nearest whole number
Math.floor(4.9) // 4 — always rounds down
Math.min(3, 7) // 3 — the smaller of the two
Math.max(3, 7) // 7 — the larger of the two