Workshop › Memory › Step 16 of 25
A turn is two cards. We keep the cards turned over this turn in a small array, opened, and refuse a third card while
two are open.
```js
let opened // the cards turned over this turn (0, 1 or 2)
opened = []
function flip(card) {
if (!card || card.faceUp || opened.length === 2) return
card.faceUp = true
opened.push(card)
}
```opened starts empty in every new game.opened.length === 2 is one more reason to refuse: two cards are already showing.opened.push(card) remembers the card turned over.let cards, write let opened.newGame, write opened = [].flip, add || opened.length === 2 to the if, and opened.push(card) at the end.Skills: Game states, Arrays and objects
← One place for the rules Pair or no pair →