Workshop › Memory › Step 17 of 25
When the second card is open: the same fruit is a pair, both are matched and stay open. Different fruits must turn
back over, but not at once, or the player never sees the second card. setTimeout waits 800 ms.
```js
if (opened.length < 2) return
const [a, b] = opened
if (a.symbol === b.symbol) {
a.matched = true
b.matched = true
opened = []
} else {
// Give the player time to see the second card before hiding both again.
setTimeout(() => {
a.faceUp = false
b.faceUp = false
opened = []
}, 800)
}
}
```const [a, b] = opened names the two open cards.matched and opened is emptied for the next turn.setTimeout turns both back over and empties opened 800 ms later. Until then opened holds two cards,
so the rule from the last step keeps a third card closed.At the end of flip, under opened.push(card), write the new lines, above the function's last }.
Skills: Game states, The game loop
← Two cards at a time Count the moves →