The game uses a fixed answer of 37, accepts whole numbers from 1 to 100, and allows ten valid guesses. Entering 50, 25, 40, and 37 wins on the fourth attempt. The displayed interval narrows after each hint until it contains only 37.

Use the worked example
Enter the four guesses one at a time, using Check or Enter after each. To see how repeated guesses behave, reset and enter 50, 25, 40, then 50 again. The repeated 50 uses an attempt, but the upper bound stays at 39. The earlier hint still applies.
Trace the result step by step
MDN’s beginner guessing example introduces a limited number of attempts, previous guesses, high/low feedback, and a restart. Here, the fixed answer makes those behaviors easy to compare: everyone following the same sequence should get the same hints. Random selection would make this particular walkthrough harder to reproduce.
The answer stays at 37 after Reset, with zero attempts and feasible bounds L = 1 and U = 100. The legal input range remains 1–100 throughout the game, while the feasible interval records what the hints establish. A legal guess outside that interval still counts as an attempt, without widening either bound.
Open the “Developer fixture key” disclosure to see the answer, or leave it closed while trying the sequence. The answer also appears in the page’s JavaScript. This fixed-answer activity is suitable for discussing validation and bounds; it cannot keep a secret from someone inspecting its source.
Trim surrounding whitespace, then reject an empty result. For this prototype, require ASCII decimal digits only, convert the whole validated string, and require a finite integer within 1–100.
This declared input syntax excludes signs, decimal points, exponent notation, hexadecimal notation and mixed characters. It is stricter than asking whether some JavaScript conversion happens to produce an integer.
MDN documents empty/whitespace strings converting to zero and parseInt stopping at an invalid numeral. Those behaviors are why conversion alone is not this game's validation. A valid-looking browser input control also does not replace the handler's complete checks. MDN: Number Coercion, MDN: parseInt
An invalid response leaves attempts, interval and valid history unchanged. Error feedback identifies the input problem separately from earlier high/low results.
A guess less than 37 is Too low, the answer is higher. A guess greater than 37 is Too high, the answer is lower. Equal 37 is a match.
The direction belongs to the answer relative to the guess. Do not reverse it by saying higher when the guess itself was too high.
After a low guess g, set L to max(previous L, g+1). After a high guess g, set U to min(previous U, g−1). Because the answer is an integer, equality with a wrong guess is excluded. A matched guess collapses L and U to 37.
For the worked sequence, 50 changes the interval to 1–49; 25 changes it to 26–49; and 40 changes it to 26–39. Those endpoints are the accumulated evidence, so a later high guess of 50 must leave 26–39 intact.
After four valid guesses, six of the ten attempts remain unused. Previous guesses are [50, 25, 40, 37] in order, each with its own feedback and interval snapshot.
Copy a prompt for this example
Create a single HTML number-guessing learning game with a fixed answer of 37, legal guesses from 1 through 100, and at most ten accepted guesses. Keep the answer in a collapsed Developer fixture key and make clear that the client-side answer is inspectable.
Provide a labeled text input, Check guess, and Reset. Trim whitespace, require the whole remaining string to contain only decimal digits, and then validate the range. Blank input, 42x, 42.5, zero, 101, and Infinity must not consume an attempt. Leading-zero digits such as 037 may represent 37.
An accepted low guess says the answer is higher; a high guess says the answer is lower. Maintain separate feasible bounds. After a low guess g, use max(old lower, g + 1); after a high guess, use min(old upper, g − 1). A repeated legal guess counts again but cannot widen either bound.
The sequence 50, 25, 40, 37 must produce bounds 1–49, 26–49, 26–39, then a win at 37–37 on attempt four, with six remaining. Preserve every accepted guess, response, and resulting bounds in order.
Check equality before the tenth-attempt loss, and ignore guesses after winning or losing. Clear the field after an accepted guess. Enter should invoke the same check once. Reset restores the same answer, initial bounds, empty history, and collapsed key. Return complete responsive HTML with readable feedback and history.
Before adding random answers to your own version, try a correct tenth guess and confirm that it wins before the attempt limit ends the round. You can preview the prepared HTML game in NOS while discussing those results. Reset afterward to return to the same answer and compare another sequence.