练习20_数字炸弹.html 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. var isPlay = window.confirm("是否开始游戏?");
  11. // console.log(isPlay);
  12. if (isPlay) {
  13. // 生成1-100的随机数字 整数
  14. var num = Math.floor(Math.random() * 100) + 1;
  15. while (true) {
  16. var res = window.prompt("请输入你的数字.");
  17. // 将文本框中的值转换成数值型
  18. res *= 1;
  19. if (res > num) {
  20. window.alert("太大了");
  21. } else if (res < num) {
  22. window.alert("猜小了");
  23. } else if (res == num) {
  24. window.alert("猜对了!!");
  25. break;
  26. } else {
  27. window.alert("输入错误");
  28. }
  29. }
  30. }
  31. </script>
  32. </body>
  33. </html>