实例题
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<input type="text" name="result" id="result" value="" />
<input type="button" id="cai" value="猜数字" />
<script type="text/javascript">
//math对象
console.log(Math.ceil(20.3))
//返回的是大于该数字的是最小整数
console.log(Math.floor(30.6))
//换回的是小于该数字的最小整数
console.log(Math.round(13.6))
//将数字进行四舍五入
console.log((Math.max(12,30,50,16)))
//求最大值两个及多个数中的最大值
console.log(Math.pow(2,3))
//随机出1~10之间的任意数字
console.log(Math.random())
console.log(Math.floor(Math.random()*11))
//数字游戏
var num=Math.floor(Math.random()*11)
console.log(num)
document.getElementById("cai").οnclick=function(){
//先获取到文本框中输入的文字
var result=Number(document.getElementById("result").value)
if(result>num){
alert("你猜的数字太大了")
}else if(result<num){
alert("你猜的数字】太小了")
}else{
alert("恭喜你猜对了")
}
}
</script>
</body>
</html>