
废话不多说了喵,上源码
<html><head><title>AnJProject-猜数字游戏</title><meta charset="UTF-8"><style>body {font-family: Arial, sans-serif;text-align: center;}h1 {margin-top: 50px;}input {padding: 10px;font-size: 20px;margin-top: 20px;}button {padding: 10px 20px;font-size: 20px;margin-top: 20px;background-color: #4CAF50;color: white;border: none;border-radius: 5px;cursor: pointer;}</style></head><body><h1>猜数字游戏</h1><p>在1到100之间猜一个数字</p><input type="text" id="guess" pattern="[0-9]+" required onkeydown="if(event.keyCode == 13) checkGuess()"><button onclick="checkGuess()">猜!</button><p id="result"></p><script>var answer = Math.floor(Math.random() * 100) + 1; // 生成1到100之间的随机数var attempts = 0;function checkGuess() {var guess = parseInt(document.getElementById("guess").value);if (guess == answer) {document.getElementById("result").innerHTML = "恭喜你,猜对了!你用了" + attempts + "次猜中了答案!";} else if (guess < answer) {document.getElementById("result").innerHTML = "你猜的数字太小了,请再试一次。";attempts++;} else if (guess > answer) {document.getElementById("result").innerHTML = "你猜的数字太大了,请再试一次。";attempts++;}}</script><footer><p>© 2023 AnJProject. All rights reserved.</p></footer></body></html>
微信扫一扫打赏
支付宝扫一扫打赏
