Workshop › Memory › Step 22 of 25
To animate a turn, we separate the truth from what is shown. card.faceUp stays the rule; a new number card.flip
goes from 0 (back) to 1 (face) and chases faceUp by 0.1 every frame.
```js
flip: 0, // 0 = showing its back, 1 = showing its face; follows faceUp over a few frames
function loop() {
for (const card of cards) {
card.flip = card.faceUp ? Math.min(1, card.flip + 0.1) : Math.max(0, card.flip - 0.1)
}
draw()
```flip: 0.flip grows by 0.1, a face-down card's shrinks by 0.1.Math.min(1, ...) never lets it pass 1, Math.max(0, ...) never below 0. It takes 10 frames to turn.newGame, under matched: false,, write the flip line.loop, above draw(), write the for loop.Skills: The game loop, Game states
← Play again Swap sides halfway →