Workshop › Memory › Step 11 of 25
A face-up card is a white square with its fruit in the middle; a face-down card stays purple. if ... else picks one
of the two ways to draw it.
```js
ctx.textBaseline = 'middle'
ctx.font = '44px sans-serif'
ctx.textAlign = 'center'
for (const card of cards) {
const x = cardX(card)
const y = cardY(card)
if (card.faceUp) {
ctx.fillStyle = '#f8fafc'
ctx.fillRect(x, y, CARD, CARD)
ctx.fillText(card.symbol, x + CARD / 2, y + CARD / 2)
} else {
ctx.fillStyle = '#6366f1'
ctx.fillRect(x, y, CARD, CARD)
}
}
```ctx lines set a 44 pixel font and make the given point the middle of the text.if (card.faceUp) { ... } else { ... }: face up draws white plus the fruit, otherwise purple.x + CARD / 2, y + CARD / 2 is the card's center.In draw, replace the card loop with the new lines (the three ctx lines go above the for).
Skills: Drawing on a canvas, Game states
← Draw again and again A fair shuffle →