猜数字游戏(JS)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var num = Math.ceil(Math.random()*100)
        var count = 1
        do{
            var num1 = prompt('请输入一个1-100数字')
            if(num1 > num){
                alert('猜大了')
            }else if(num1 < num){
                alert('猜小了')
            }else{
                alert('恭喜你在第' + count + '次猜中了')
            }
            count++
        }while(num1 != num)
    </script>
</body>
</html>
发布了60 篇原创文章 · 获赞 3 · 访问量 534

猜你喜欢

转载自blog.csdn.net/dfc_dfc/article/details/105521608