Math is a built-in object that has properties and methods for mathematical constants and functions. It’s not a function object.
floor
Math.floor()
function returns the largest integer less than or equal to a given number.
1 | console.log(Math.floor(5.95)); |
random
Math.random()
returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1). Example 0.9448960908626425
Using floor
and random
together:
1 | function getRandomInt(max) { |