猜数字游戏的网页

360影视 2025-01-25 16:31 2

摘要:猜数字游戏body{font-family:'SegoeUI',Tahoma,Geneva,Verdana,sans-serif;display:flex;justify-con

猜数字游戏body {font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;display: flex;justify-content: center;align-items: center;height: 100vh;margin: 0;background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);color: #333;}.game-container {background-color: rgba(255, 255, 255, 0.9);padding: 30px;border-radius: 20px;box-shadow: 0 10px 30px rgba(0,0,0,0.2);text-align: center;max-width: 400px;width: 90%;}h1 {color: #4a4a4a;margin-bottom: 20px;font-size: 2.5em;text-shadow: 2px 2px 4px rgba(0,0,0,0.1);}p {color: #666;line-height: 1.6;}input {width: 120px;padding: 10px;margin: 20px 0;border: 2px solid #ddd;border-radius: 5px;font-size: 1em;text-align: center;}button {background-color: #6c5ce7;color: white;border: none;padding: 12px 25px;font-size: 1em;margin: 10px 0;cursor: pointer;border-radius: 50px;transition: all 0.3s ease;box-shadow: 0 5px 15px rgba(108, 92, 231, 0.4);}button:hover {background-color: #5b4cdb;transform: translateY(-2px);box-shadow: 0 7px 20px rgba(108, 92, 231, 0.6);}#message {margin-top: 20px;font-weight: bold;color: #2d3436;padding: 10px;border-radius: 10px;background-color: rgba(255, 255, 255, 0.7);}

猜数字游戏

我已经想好了一个1到100之间的数字,你能猜出来吗?

猜!

let targetNumber = Math.floor(Math.random * 100) + 1;let attempts = 0;function checkGuess {let guess = parseInt(document.getElementById('guessInput').value);attempts++;if (isNaN(guess) || guess 100) {setMessage('请输入1到100之间的有效数字!');return;}if (guess === targetNumber) {setMessage(`恭喜你!你猜对了!答案就是 ${targetNumber}。你总共猜了 ${attempts} 次。`);document.querySelector('button').disabled = true;} else if (guess

运行效果:

来源:MLI搞怪

相关推荐