Workshop › Klondike Solitaire › Step 7 of 40
Klondike is a game of piles: the stock (face down) and the waste next to it, four foundations where each suit
is built up from the ace, and seven tableau columns. We keep them all in one object, piles, each pile an array of
cards. deal starts with the whole deck in the stock.
```js
let piles // stock, waste, f0..f3 (foundations) and t0..t6 (tableau): arrays of { rank, suit, up }
function deal() {
const deck = newDeck()
piles = { stock: [], waste: [] }
for (let f = 0; f < 4; f++) piles['f' + f] = []
piles.stock = deck
}
deal()
```let piles is empty until deal fills it.piles = { stock: [], waste: [] } makes an object with two empty piles.piles['f' + f] = [] adds a key made of text: 'f' + 0 is 'f0'. So the loop adds f0 to f3.piles.stock = deck: the shuffled deck becomes the stock.deal() above requestAnimationFrame(loop) deals once when the page loads.const CH = 78 leave an empty line and write let piles ... with its comment.newDeck, leave an empty line and write deal.deal() just above the last line, requestAnimationFrame(loop). Press Run.Skills: Arrays and objects, Game states
← Shuffle Deal the seven columns →