This was more involved than I expected for a phone screen.
Start by clarifying requirements and test expectations, then outline a component architecture with clear separation of concerns: data fetching, game state, and UI rendering. Emphasize testability by mocking the HTTP endpoint and designing pure functions for feedback logic.
Pro tip: Mention that you'll handle edge cases like duplicate letters in guesses and target words, and ensure the feedback algorithm correctly marks letters as present only once per occurrence. Also, discuss how you'd structure the code to make it easy to swap the data source or add features like keyboard input.
Ask about the endpoint's response format, how tests mock it, and any constraints on dependencies. Confirm the rules: 6 attempts, feedback per letter, win/loss conditions.
Plan a main Game component that fetches the word and manages state (guesses, current guess, game status). Use child components for the board and keyboard, and keep feedback logic in a pure utility function.
Use fetch or axios to get the target word on mount, with loading and error states. Ensure the fetch is mockable in tests, e.g., by injecting a fetch function or using a library like MSW.
Write a function that takes a guess and target, returns an array of statuses (correct, present, absent). Handle duplicate letters by tracking counts. Update state on guess submission and check for win/loss.
Write unit tests for the feedback function and component tests with mocked endpoint. Cover cases like duplicate letters, invalid guesses, and game over. Discuss how to structure code for easy testing.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.