【JS】课本p88猜数字游戏

Osinghong6个月前 (04-21)成果展示82
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>d24c04429</title>
<body>
    <script>
        function getRandom(min,max){
            return Math.floor(Math.random()*(max - min + 1)+ min)
        }
        var random = getRandom(1,10);
        while(true){
            var num = prompt('请输入一个1-10的整数:')
            if (num ===null) {
                break;
            } else if (num > random){
                alert("你猜大了");
            } else if (num < random){
                alert("你猜小了");
            } else {
                alert("恭喜你,猜对了!");
                break;
            }
        }
    </script>
</body>
</html>


打赏
分享给朋友:

相关文章

【H5】页面布局练习11个月前 (12-05)
【JS】关于continue7个月前 (03-24)
【JS】循环嵌套7个月前 (03-24)
【JS】倒三角形7个月前 (03-24)