Wordle-style game with graded guesses and a letter tracker
Build a five-letter word guessing game. The player has six tries to find a secret word. After each guess, every letter is graded: in the right spot, in the word but elsewhere, or not in the word. A letter tracker below the board shows what the player has learned about each letter so far.
The starter code includes the game data. The secret is fixed so the game is predictable to test:
const SECRET = 'GREET';
const WORDS = ['GREET', 'TEPEE', 'ENTER', 'STORM', 'PLANT', 'CHAIR', 'LEMON', 'BRICK', 'QUILT', 'MANGO', 'TIGER', 'OCEAN', 'FROST', 'CLOUD', 'PIXEL'];
const WORD_LENGTH = 5;
const MAX_GUESSES = 6;
const KEYBOARD_ROWS = ['QWERTYUIOP', 'ASDFGHJKL', 'ZXCVBNM'];
Guess (a <label> or aria-label). Pressing Enter in it submits the guess. A <form> with an onSubmit handler (plus a submit button if you like) or an Enter keydown handler both work. Use one, not both. enter is the guess ENTER.Enter 5 lettersWORDS: Not in word listAlready guessedA valid guess clears the input and hides the message.
aria-label="<LETTER>, <status>", where status is correct, present or absent (for example aria-label="E, correct"). Every other tile has aria-label="empty".SECRET:
correct: same letter in the same position.present: the letter is elsewhere in the secret and not used up by a correct tile or an earlier present tile.absent: otherwise.KEYBOARD_ROWS (all 26), showing the letter, with aria-label="Key <LETTER>, <status>". Status is unused until the letter appears in a guess, then the best status it has had in any guess: correct beats present, which beats absent. A key never gets downgraded.SECRET shows Solved in N guesses! (Solved in 1 guess! for one).Out of guesses. The word was GREET.Secret: GREET
Guess STORM S absent, T present, O absent, R present, M absent
Guess TEPEE T present, E present, P absent, E correct, E absent
Guess ENTER E present, N absent, T present, E correct, R present
Guess GREET all correct "Solved in 4 guesses!"
Tracker after STORM, TEPEE and ENTER:
E correct (correct in TEPEE beats present and absent)
T present, R present
S, O, M, P, N absent
G unused
Guess GRE "Enter 5 letters"
Guess ABCDE "Not in word list"
Guess STORM (again) "Already guessed"
TEPEE, the secret GREET has two Es: the fourth E is correct and uses one, the second E is present and uses the other, so the fifth E is absent. Mark correct tiles first, then hand out present from the letters left over, left to right.GR3ET and GREETS are not 5 letters A–Z.GRE shows Enter 5 letters, not Not in word list.The tests type into the input labelled Guess, press Enter, and read the screen like a user would. You don’t need test ids, specific class names, or an exact HTML structure. They check that:
aria-label is empty or <LETTER>, <status>, in DOM order (row by row).aria-label is Key <LETTER>, <status>, in any order.Capitalization and extra spacing don’t matter.