JavaScript Hangman: Count Guesses by Letter, Not Revealed Positions

The player guesses L in BALLOON. Two positions should open, but only one letter was guessed.

Another player enters Z twice with different capitalization; charging two misses would penalize the same guess again. A letter game needs one normalized guess record to drive the display and remaining attempts.

This original JavaScript hangman source plan uses neutral attempt markers and a fixed developer word. It includes no hanging-body artwork, working interface or executed game.

Letter lab · JavaScript word game
Letter lab · JavaScript word game
Open the full example ↗

Define the word and the attempt policy

The developer fixture is BALLOON, seven positions. Start with seven unrevealed slots. The miss budget is six distinct incorrect letters, an explicitly chosen variant.

Stanford's archived WordGuess assignment describes revealing every occurrence of a guessed letter and ending when the word is found or the miss budget is exhausted. Its budget is eight; this plan's six is an original rule, not a universal hangman standard. WordGuess Assignment

Use the original word list BALLOON / PLANET only for the proposed new-game option. No source assignment words, list or code are copied. The local answer is inspectable in source; “secret word” is a play convention, not a security guarantee.

Use a single guessed-letter set

Accept one ASCII letter A–Z, case-normalized. Reject empty, digit or multi-letter input without changing the game. Both a native letter button and any optional text-entry submit must call the same guess operation.

Before adding a normalized letter, check whether it is already in the guessed set. A repeated letter produces explanatory feedback but no new guess or miss. Derive the masked word and miss count from this authoritative set rather than independently incrementing several counters.

Actual input and control behavior remain untested. The source plan states the contract; it does not report a player session.

Reveal every matching position

Use these original fixture checks, with positions numbered from one:

Guess at a fresh baseline Revealed positions Display Misses
L 3 and 4 _ _ L L _ _ _ 0
O 5 and 6 _ _ _ _ O O _ 0
Z None _ _ _ _ _ _ _ 1

In one successful sequence, B, A, L, O, N reveal all seven positions. Five distinct correct letters account for a seven-letter word because L and O each occur twice.

For a separate miss sequence, Z is added once. A later lowercase z normalizes to that same letter and leaves the miss count at one. Then X, Q, V, J and K bring the total to six distinct misses. These letters are absent from BALLOON, so that sequence loses under the declared budget.

Make terminal states explicit

The win condition is that every word position is revealed. The loss condition is six distinct misses. After either terminal state, further guesses must be ignored and state preserved until reset or a new game.

Show six neutral remaining-attempt markers with a textual count and the guessed-letter record. They communicate the rule without violent imagery. Invalid or repeat guesses should not silently consume a marker.

Reset fixture keeps BALLOON and clears the guessed set, display, misses and terminal state. New game selects a word from the original two-word list and clears the same state. Keep those controls distinct; the plan includes no daily puzzle, streak or stored best score.

Prepare an evidence-focused test matrix

The native test record should cover repeated-position reveals, normalized repeat guesses, invalid input, the successful sequence, the six-miss sequence, terminal guards and reset/new-game behavior. Record expected masks and remaining attempts as fixture data.

After authorized implementation, test letter buttons and optional entry, keyboard focus, narrow-screen layout and the intended host. Do not mark those checks passed from reading the algorithm. No network, score collection or saved progress is included.

Copy this prompt for the letter-game plan

Prepare an original US-English JavaScript letter-guess source plan with neutral attempt markers, native fixture/key and test matrix; no actual HTML/JS/game run. Developer word BALLOON seven positions; original list BALLOON/PLANET for New game. Six distinct miss budget explicitly original variant, not Stanford's eight or universal rule. No hanging-body art.

Accept one ASCII A–Z case-normalized, invalid empty/digit/multiletter no change. One guessed set derives mask/misses/terminal. Duplicate normalized letter feedback no extra guess/miss; Z then z counts once. L reveals positions 3/4, O positions 5/6, each one unique guess. B,A,L,O,N reveals all 7 and wins. Separate Z,X,Q,V,J,K absent letters give 6 misses and lose. All positions revealed win; six distinct misses loss; ignore further guesses after terminal.

Native 26 letter buttons/optional entry use the same operation; text feedback, guessed letters and six remaining markers. Reset fixture preserves BALLOON and clears state; New game chooses from the original list/clears state. Local word inspectable, not hidden-answer security. No daily/streak/storage/network/copied source word/code. Native source/test record primary; actual keyboard/input/360px/host tests pending, no learning/efficacy claim.

Review the guess beside the revealed letters

The local HTML game places the letter controls, masked word and distinct-miss explanation together. NOS supports saving and rendering prepared HTML; verify guessing and reset in the intended host. Retain the native source plan and test record.

Explore NOS to present the prepared guess review. A player should see every matching position and understand why one repeated letter cannot consume another attempt.

Keep reading