Math对象其实就是数学对象,它给我们提供了各种各样的数学功能。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>首页</title>
</head>
<body>
<script type="text/javascript">
a = Math.abs(1)
b = Math.abs(-1)
console.log(a,b)
</script>
</body>
</html>
<script type="text/javascript">
a = 1
b = 10
c = 100
n = Math.max(a,b,c)
console.log(n)
</script>
<body>
<button type="button" onclick="getRandom(5,10)">random</button>
<script type="text/javascript">
function getRandom(min,max){
result = Math.random() * (max - min) + min
result = Math.floor(result)
alert(result)
}
</script>
</body>
随机生成min到max之间的数。