example_of_js_1.html 563 B

12345678910111213141516171819202122232425262728
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>猜数字</title>
  6. </head>
  7. <body>
  8. <script>
  9. var answer = parseInt(Math.random() * 100 + 1)
  10. var counter = 0
  11. var yourInput
  12. do {
  13. counter += 1
  14. yourInput = prompt('请输入你猜的数字: ')
  15. if (yourInput > answer) {
  16. alert('小一点')
  17. } else if (yourInput < answer) {
  18. alert('大一点')
  19. } else {
  20. alert('恭喜你猜对了')
  21. }
  22. } while (answer != yourInput)
  23. if (counter > 7) {
  24. alert('智商余额不足')
  25. }
  26. </script>
  27. </body>
  28. </html>