Workshop › Klondike Solitaire › Step 19 of 40
In a tableau column a card goes on a face-up card one rank higher and of the other color: a red 9 on a black 10.
Only a king may start an empty column. canStack answers "may this card go on this pile?" and changes nothing.
```js
// Tableau: one lower, the other color; only a king goes into an empty column.
function canStack(card, pile) {
const under = last(pile)
if (!under) return card.rank === 13
return under.up && under.rank === card.rank + 1 && isRed(under) !== isRed(card)
}
```under is the card it would go on. For an empty pile it is undefined, so !under is true: only a king.&& must all be true: under is face up, one rank higher, and of the other color.isRed(under) !== isRed(card): two true/false values differ exactly when one card is red and the other is not.Under cardY, leave an empty line and write canStack with its comment.
Skills: Functions
← Tap the stock Rule 2: building a foundation →