javascript的进阶运算(对象)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
            console.log(Math.ceil(12.9))//返回的是大于该数字的最小整数
            console.log(Math.floor(12.9))//返回的是小于该数字的最大整数
            console.log(Math.round(12.9))//将数进行四舍五入
            console.log(Math.max(12,9,62,16))//求最大值 两个数及多个数的最大值
            console.log(Math.pow(2,9))//2的9次方
            console.log(Math.random())//随机产生0-1之间的任意数字[0,1)
            console.log(Math.floor.random()*11)

            
        </script>
    </body>
</html>

2.<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <input type="text" name="result" id="result">
        <input type="button" id="cai" value="猜数字">
        <script type="text/javascript">
            //猜数字游戏
            var num = Math.floor(Math.random() * 11)
            console.log(num)
            document.getElementById("cai").onclick = function() {
                for (i = 1; i < 5; i++) {
                    var result = Number(document.getElementById("result").value)
                    if (result == num) {
                        alert("你赢了")
                        break
                    } else if (result > num) {
                        alert("你输入的数太多")
                        i++
                        continue
                    } else if (result < num) {
                        alert("你输入的数太小")
                        i++
                        continue
                    }
                    if (i >= 5) {
                        console.log("你输了")
                    }
                }
            }
        </script>
    </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值