我創(chuàng)建了一個(gè)數(shù)字猜謎游戲,您在其中輸入數(shù)字作為用戶(hù)并嘗試獲取與計(jì)算機(jī)選擇的數(shù)字相同的數(shù)字。計(jì)算機(jī)會(huì)在1-100之間選擇一個(gè)數(shù)字,每次您猜測(cè)時(shí),它都會(huì)告訴您是否需要猜測(cè)更高或更低。問(wèn)題出在Java腳本中,我正在考慮是寫(xiě)錯(cuò)了東西還是不是應(yīng)該寫(xiě)的東西。我已經(jīng)檢查了所有ID和所有內(nèi)容,但仍未從代碼中獲得任何反饋。我希望代碼在嘗試按下猜測(cè)按鈕時(shí)能夠輸出某些內(nèi)容<!DOCTYPE html><html><head> <title>GuessingGame</title> <style> </style> <script> var playerGuess = document.getElementById("guessInput").value; var computerGuess = Math.floor(Math.random() * 10 + 1); var playAgain = true; function randNum(low, high) { var number = Math.floor(Math.random() * high + low); return number } function guessNumber() { if (playerGuess > computerGuess) { document.getElementById("output").innerHTML = "Guess lower" } else if (playerGuess < computerGuess) { document.getElementById("output").innerHTML = "Guess higher" } else(playerGuess == computerGuess) { document.getElementById("output").innerHTML = "Good job you guessed right" } </script></head><body> <h1>Guessing Game</h1> <h2>The computer will choose a number between 1 and 100</h2> <h2>You have to try and guess what it picked</h2> <span><input type="number" id="guessInput"> <button onclick="guessNumber();">Guess</button><button onClick="reset();">Reset</button> <p id="output"></p> </body> </html>
猜謎游戲可能出現(xiàn)的語(yǔ)法錯(cuò)誤
白衣非少年
2021-05-13 10:16:17