Build a simplified Wordle game in React
Problem: Implement a Simplified Wordle Game in React
Build a small, Wordle-like game user interface using React.
Requirements
- The game must choose a single answer word by fetching it from a provided HTTP endpoint.
- The exact endpoint URL will be supplied (treat it as given).
- Assume the endpoint returns a JSON payload containing the answer word (e.g.,
{ "answer": "react" }) or a plain text word. The chosen assumption should be stated in the code.
- The answer word length is fixed (commonly 5 characters).
- The player has a fixed number of attempts (commonly 6).
Gameplay
- The player enters guesses one row at a time.
- Upon submitting a guess:
- If the guess length does not exactly match the answer word length, an error should be shown, or the submission should be ignored.
- Otherwise, compute per-letter feedback for the submitted guess:
- Correct: The letter is in the correct position.
- Present: The letter exists in the answer word but in a different position.
- Absent: The letter does not exist in the answer word.
- Handle duplicate letters correctly, following standard Wordle-style counting rules.
- Game end conditions:
- If the submitted guess equals the answer word, the player wins, and no further input should be accepted.
- If all attempts are exhausted, the player loses, and the answer word must be revealed.
UI Expectations
- The UI should render a grid representing the game board, with dimensions corresponding to the number of attempts by the word length.
- It must display the current typing state (the word being actively entered) and all previously committed guesses with their respective feedback.
- Input can be handled either via an on-screen keyboard component or by capturing physical keyboard input (letters, Backspace, Enter).
- Crucially, the UI implementation must be testable.
Deliverable
Implement the necessary React component(s) and supporting logic to ensure the game functions end-to-end, from fetching the answer word, through playing multiple rounds, to rendering appropriate feedback and handling game end states.
Notes
- You are encouraged to use React hooks (
useState,useEffect, etc.). - Styling is not a primary focus; implement only what is required for functional rendering and clear presentation.
AI interview prep
Core dilemma
Balancing efficient and testable React state management for complex UI interactions and game logic, while ensuring a robust and accessible user experience.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Build a simplified Wordle game in React
Problem: Implement a Simplified Wordle Game in React
Build a small, Wordle-like game user interface using React.
Requirements
- The game must choose a single answer word by fetching it from a provided HTTP endpoint.
- The exact endpoint URL will be supplied (treat it as given).
- Assume the endpoint returns a JSON payload containing the answer word (e.g.,
{ "answer": "react" }) or a plain text word. The chosen assumption should be stated in the code.
- The answer word length is fixed (commonly 5 characters).
- The player has a fixed number of attempts (commonly 6).
Gameplay
- The player enters guesses one row at a time.
- Upon submitting a guess:
- If the guess length does not exactly match the answer word length, an error should be shown, or the submission should be ignored.
- Otherwise, compute per-letter feedback for the submitted guess:
- Correct: The letter is in the correct position.
- Present: The letter exists in the answer word but in a different position.
- Absent: The letter does not exist in the answer word.
- Handle duplicate letters correctly, following standard Wordle-style counting rules.
- Game end conditions:
- If the submitted guess equals the answer word, the player wins, and no further input should be accepted.
- If all attempts are exhausted, the player loses, and the answer word must be revealed.
UI Expectations
- The UI should render a grid representing the game board, with dimensions corresponding to the number of attempts by the word length.
- It must display the current typing state (the word being actively entered) and all previously committed guesses with their respective feedback.
- Input can be handled either via an on-screen keyboard component or by capturing physical keyboard input (letters, Backspace, Enter).
- Crucially, the UI implementation must be testable.
Deliverable
Implement the necessary React component(s) and supporting logic to ensure the game functions end-to-end, from fetching the answer word, through playing multiple rounds, to rendering appropriate feedback and handling game end states.
Notes
- You are encouraged to use React hooks (
useState,useEffect, etc.). - Styling is not a primary focus; implement only what is required for functional rendering and clear presentation.