最大值与最小值随笔

作者: 码农也会修真 | 来源:发表于2019-06-09 20:57 被阅读4次
console.log(Math.max(1, 2, 3, 4, 5, 6)); // 取最大值
console.log(Math.min(1, 2, 3, 4, 5, 6)); // 取最小值
console.log(Math.min(1, 2, 3, 'a', 5, 6)); // 有字符串所以打不出来
console.log(Math.ceil(10.1)); // 向上取整天花板
console.log(Math.floor(10.9)); // 向下取整地板

console.log(Math.round(10.5)) // 四舍五入
console.log(Math.round(10.4)) // 四舍五入


console.log(Math.abs(10)); // 绝对值
console.log(Math.pow(2, 4)); // pow:2的4次方 
console.log(Math.sqrt(16)) // 16的开方
console.log(Math.floor(Math.random() * 10)); // low随机数乘的数只能是10以下的数

// //结束值 + 起始值

// // 起始值  <=  范围  <= 结束值


var str = 'ABCDEFGHI';
setInterval('console.log(str[Math.floor(Math.random()*10)]);', 1000) 
// 随机每隔1秒打印一下函数str

相关文章

网友评论

    本文标题:最大值与最小值随笔

    本文链接:https://www.haomeiwen.com/subject/khfoxctx.html