Memory Game
UI Coding
Medium
40 min
games
state
timers
effects
accessibility
Build a memory (concentration) game. A grid of face-down cards holds pairs of symbols. The player turns over two cards per move. A matching pair stays face up. A mismatched pair is shown briefly, then turns back over.
The starter renders a grid of face-down cards from SYMBOLS and exports a MemoryGame component.
API
export function MemoryGame({
symbols = SYMBOLS, // [{ name: 'Apple', emoji: '🍎' }, …], one entry per pair
shuffle = shuffleArray, // (cards) => shuffled copy; tests pass an identity function
mismatchDelay = 1000, // ms a mismatched pair stays visible
})
Requirements
- The deck holds two cards per symbol, shuffled. Write an unbiased shuffle.
- Clicking a face-down card turns it over. Clicking a face-up or matched card does nothing.
- When a second card is turned:
- Match: both stay face up and are marked as matched.
- Mismatch: both stay visible for
mismatchDelayms, then turn back over. - Either way, the move counter goes up by one.
- If the player clicks a third card while a mismatched pair is still showing, turn the pair back over immediately and flip the new card. Don't make players wait.
- When every pair is matched, show
You found all N pairs in M moves!and a New game button that reshuffles. - Accessibility:
- Each card is a button named by position and state:
Card 3, face down,Card 3, AppleorCard 3, Apple, matched. - Results ("Match: Apple" / "No match: Apple and Pear") and the final message are announced through a
role="status"region. - Don't leak face-down symbols to assistive tech, for example via
alttext or hidden DOM.
- Each card is a button named by position and state:
- Clean up the flip-back timer when the component unmounts or the game resets.
Follow-up
- Add a timer and a best-score record that persists across reloads.
- Arrow-key navigation over the grid (roving tabindex).
- The 3D flip is janky on low-end phones. Why, and how would you animate it?
Spotted a mistake or a rights concern? Report an issue