Workshop › Klondike Solitaire › Step 10 of 40
Now draw goes through every pile and draws its cards: the top row at TOP_Y, the tableau columns lower, at TAB_Y.
The test card goes away.
```js
const TOP_Y = 40 // the stock, the waste and the foundations
const TAB_Y = 136 // the seven tableau columns
for (const [key, pile] of Object.entries(piles)) {
const x = pileX(key)
// The stock, the waste and the foundations only need their top card.
const first = key[0] === 't' ? 0 : Math.max(0, pile.length - 1)
for (let i = first; i < pile.length; i++) drawCardAt(pile[i], x, key[0] === 't' ? TAB_Y : TOP_Y)
}
```Object.entries(piles) turns the object into a list of [name, pile] pairs; for (const [key, pile] of ...)
runs once per pair, putting the name in key and the array in pile.first is where drawing starts: 0 for a column (every card), the last index for the other piles.
Math.max(0, ...) keeps it from going below 0 for an empty pile.TAB_Y for now.COL write TOP_Y and TAB_Y.draw, replace the test card line with the for loop. Press Run.Skills: Drawing on a canvas, Loops
← A place for every pile Fan out the columns →