Memory card game with flip pairs, move counter, and win state
Build a space-themed pairs game. Twelve cards lie face down in a 4 × 3 grid, and every card has exactly one twin. The player flips two cards per turn: twins stay face up, anything else turns back over after a short pause. The game ends when every pair is found.
The starter code includes the deck and the pause length:
const DECK = ['Comet', 'Moon', 'Rocket', 'Sun', 'Moon', 'Star', 'Planet', 'Comet', 'Sun', 'Rocket', 'Star', 'Planet'];
const FLIP_BACK_MS = 1000;
The deck is already shuffled, so the game is predictable to test. Render the cards in this order (row by row, 4 per row) and don’t reshuffle.
<button>. A face-down card shows no name (for example a ?) and has aria-label="Card N, face down", where N is its 1-based position. A face-up card shows its name as text.Moves: N, starting at Moves: 0. A move is a turn: it counts when the second card of a turn is flipped.disabled attribute or aria-disabled="true"), and clicking them does nothing.FLIP_BACK_MS milliseconds, then both turn face down.You won in N moves!.Moves: 0, no win message, and any pending flip-back cancelled.Click card 2 (Moon), card 5 (Moon) both stay face up, disabled. Moves: 1
Click card 1 (Comet), card 3 (Rocket) both face up. Moves: 2
...1000 ms later cards 1 and 3 turn face down
Click card 1 (Comet), card 3 (Rocket) both face up. Moves: 1
Click card 4 right away cards 1 and 3 turn face down now, card 4 (Sun) face up. Moves: 1
...1000 ms later card 4 is still face up
Find all six pairs with one miss "You won in 7 moves!"
The tests click your buttons and read the screen like a user would. You don’t need test ids, specific class names, or an exact HTML structure. They replace setTimeout and clearTimeout with a fake clock and move it forward by hand, so schedule the flip-back with setTimeout(…, FLIP_BACK_MS) (not setInterval, requestAnimationFrame, or a CSS transition event). They check that:
role="button" elements) other than Play again, in DOM order. A card is face up when its text contains its name (Comet, Moon, Rocket, Sun, Star or Planet) and face down when it contains none.Moves: N and You won in N moves appear as described.Capitalization and extra spacing don’t matter.