max
x と y のうち、大きいほうの値を返します。
Math.max(x, y);
Node.js CLI
console.log(Math.max(10, 4)); // 10
x と y のうち、大きいほうの値を返します。
Math.max(x, y);
console.log(Math.max(10, 4)); // 10
x と y のうち、小さいほうの値を返します。
Math.min(x, y);
console.log(Math.min(10, 4)); // 4
値の小数点以下を四捨五入します。
console.log(Math.round(0.1)); // 0
console.log(Math.round(0.5)); // 1
値の小数点以下を切り上げします。
console.log(Math.ceil(0.1)); // 1
console.log(Math.ceil(0.5)); // 1
console.log(Math.ceil(1.385)) // 2
値の小数点以下を切り捨てます。
console.log(Math.floor(0.15)); // 0
console.log(Math.floor(10.3)); // 10
0 以上 1 未満の擬似乱数を返します。
console.log(Math.random());
// 0 ~ 9 の整数を返す
console.log(Math.floor(Math.random() * 10));
let min = 10
let max = 20;
let num = Math.floor( Math.random() * (max + 1 - min) ) + min;
console.log(num);