第十二次作业

第12次作业-Math对象猜数字游戏

| 这个作业属于哪个课程 | https://edu.cnblogs.com/campus/sdscfz/SF3 |

| ---------- | -------------------------------------------------------- |
| 这个作业要求在哪里 | https://edu.cnblogs.com/campus/sdscfz/SF3/homework/12980 |
| 这个作业的目标 | 第12次作业-Math对象猜数字游戏 |

代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>猜数字</title>
</head>
<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>random){
                alert('猜的大了'); 
            }
            else if(num<random)
                alert('猜的小了');
            }
            else {
                    alert('猜对了');
                    break;
            }
        }
    </script>
</body>
</html>
posted @ 2023-05-29 08:23  大头abc  阅读(17)  评论(0编辑  收藏  举报