1.Math对象:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
/*
* Math
* - Math可以用来做数学运算相关的操作
* - Math并不是一个构造函数,我们也不需要去创建一个Math类型
* - Math是一个工具类,它里面封装了一些数学运算相关的常量和方法
*/
/*
* Math中的常量
* Math.PI 圆周率
*/
//console.log(Math.PI);
/*
* Math.abs()
* - 可以用来获取一个数的绝对值
*/
//console.log(Math.abs(10));
/*
* Math.ceil()
* - 可以对一个数进行向上取整
* - 只要小数点后有值就向上进1
*/
//console.log(Math.ceil(1.000001));
/*
* Math.floor()
* - 可以对一个数进行向下取整
* - 小数点后的值都舍去
*/
//console.log(Math.floor(1.01));
/*
* Math.round()
* - 对一个数进行四舍五入取整
*/
//console.log(Math.round(5.4));
/*
* Math.random();
* - 可以生产一个0-1之间的随机数
*
* - 生成一个 0-10 之间的随机数
* 生成 0 - x 之间的随机数
* Math.round(Math.random()*x)
*
* 生成一个 1 - 6之间的随机数
* 生产一个 x - y之间的随机数
* Math.round(Math.random()*(y-x) + x)
*
* 生成一个 1-8之间的随机数
* 生成一个 22-30之间的随机数
*
*/
for(var i=0 ; i<100 ; i++){
//console.log(Math.round(Math.random()*5));
//console.log(Math.round(Math.random()*8 + 22));
}
/*
* Math.max()
* - 可以从多个值中获取到最大值
* Math.min()
* - 获取多个值中的最小值
*/
var result = Math.max(100,20,55,77);
result = Math.min(100,20,55,77);
//console.log(result);
/*
* Math.pow(x,y)
* - 获取x的y次幂
*/
result = Math.pow(3,3);
/*
* Math.sqrt(x)
* - 求一个数的平方根
*/
result = Math.sqrt(2);
//console.log(result);
</script>
</head>
<body>
</body>
</html>