The Math Object
Math has ready-made helpers: Math.round, Math.floor, Math.ceil, Math.trunc, Math.abs, Math.sqrt, Math.pow, Math.max, Math.min and constants such as Math.PI.
round goes to the nearest whole number, floor always down and ceil always up.
Example
console.log(Math.round(4.5), Math.floor(4.9), Math.ceil(4.1));
console.log(Math.sqrt(81), Math.pow(2, 8), Math.abs(-7));
console.log(Math.max(3, 9, 5), Math.min(3, 9, 5));
console.log(Math.PI.toFixed(4));Exercise
Always round down.
Math.(4.9)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.