javaScript中math的对象

 

 实例题

 <!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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值