JS realizes a guess digital game

See you need to guess a few times to guess the correct number!

The code is as follows: js实现一个猜数字游戏

 guess digital game   window.onload = newgame; // When the page is loaded, you start a new game. Window.onpopState = POPSTATE; // Hands history related events var state, ui; // global variable, initialization newgame (Playagain) {ui = {heading: null, // document is the most in the newgame () method The above  element prompt: null, / / ​​Require user input a guess number INPUT: NULL, // User Enter Guess number Low: Null, // Visualized three table cell MID: null, // Guess Digital range high: null,}; // Query the ID for (VAR ID IN UI) UI [ID] = Document.GetElementById (ID) of each element in these elements; // Defines an event handler function to the INPUT field Ui.input.onchange = handlegues; // Generate a random number and initialize the game statusState = {N: Math.Floor (99 * math.random ()) + 1, // Eightener: 0  State.low) && (g  state.n) state.high = g; state. Guess = g; state.guessnum ++; // Save a new status save (state) in the browser history; // modify document Display (state) according to user guessing;} Else {// invalid speculation: Do not save State Alert ("Please enter greater than" + state.low + "and less than" + state.high);}} // Modify the document to display the navigation and title UI of the game current statly display (state) {// display document. Heading.innerhtml = document.title = "I am thinking about the number between" + state.low + "to" + state.high + "!"; // use a table to display the number of value range UI.low .style.width = state.low + "%"; ui.mid.style.width = (state.high-state.low) + "%"; ui.high.style.width = (100-state.high) + "%"; // Make sure the input field is visible, empty and is focused UI.input.style.visibility = "visible"; ui.input.value = ""; ui.input.focus (); // According to recent speculation user, set reminders if (state.guess === undefined) ui.prompt. Innerhtml = "Enter your guess:"; else if (state.guess  state.n) ui.prompt.innerhtml = state.guess + "high, then guess:"; Else {// When guess When you have hidden the input field and display "play again" button ui.input.style.visibility = "hidden"; ui.Heading.innerhtml = Document.title = state.guess + "correct!"; Ui.prompt .innerhtml = "You won  play again ";}} 

< n #prompt {font-size: 16pt;} Table {Width: 90%; Margin: 10px; margin-left : 5%;} #low, #high}; height: 1em;} # MID} < state.high)) { //对应的更新状态 if (g I am thinking of a number.

The above is the full content of this article, and it is desirable to bring certain help to everyone's learning or work, and I hope to support Tumi Cloud!
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment