Workshop › Klondike Solitaire › Step 2 of 40
A card is a small object: { rank, suit, up }. drawCardAt draws one at a given place: white if it is face up, blue if
it is face down, with a thin dark border. We try it on one test card.
```js
const CW = 56 // card width
const CH = 78
function drawCardAt(card, x, y) {
ctx.fillStyle = card.up ? '#ffffff' : '#1d4ed8'
ctx.fillRect(x, y, CW, CH)
ctx.strokeStyle = '#0f172a'
ctx.lineWidth = 1
ctx.strokeRect(x, y, CW, CH)
}
drawCardAt({ rank: 12, suit: 1, up: true }, 16, 40)
```CW and CH are the card's width and height, named once.card.up ? '#ffffff' : '#1d4ed8' is the conditional operator: white if card.up is true, blue otherwise.strokeRect draws only the outline of a rectangle, in strokeStyle, lineWidth pixels thick.draw draws a face-up test card (a queen of hearts) at (16, 40). It is temporary.const ctx = ... leave an empty line and write CW and CH.function draw() { write drawCardAt, with an empty line between them.draw, after the fillRect line, leave an empty line and write the test call. Press Run.Skills: Drawing on a canvas, Functions
← The green table The face of a card →