The aim of this puzzle: Add a card to your hand in the takeTurnAndShowHand
function.
Walkthrough of the solution: There is a function called drawCard
that produces a random card from a deck. You want to use that function to get a card and then add that card to your hand before showing it. The cards in your hand are stored in an array called myHand
– you can add an item to the bottom of an array using .push()
. That means you can draw a card and add it to your hand using myHand.push(drawCard());
Just remember to use this command inside of the takeTurnAndShowHand
function before the print loop.
Sample code solution:
(Tap below to reveal)
function drawCard(){
return {
value: pickRandom(13),
suit: pickRandom([
'hearts',
'diamonds',
'clubs',
'spades'
])
};
}
function takeTurnAndShowHand(){
myHand.push(drawCard());
for (var card of myHand){
print(card.value + ' of ' + card.suit);
}
}
takeTurnAndShowHand();
JavaScript Concepts: Binary Expression (+ concatenation), Code Block (function), Calling Functions, Call Nesting
Grasshopper Concepts: pickRandom()