liveBook · Manning

Card game

As explained in Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond

A game played with a deck of cards according to rules that define how cards are dealt, ranked, and used to determine outcomes.

A card game models cards, a deck, and rules for dealing and scoring. In a Blackjack implementation, each card stores a suit and face, while collections track available cards and game state. section 26.1

A practical card-game model handles the following:

  • Store suits and faces in Sets, and map most face names to numeric values. section 26.1
  • Create a 52-card deck, shuffle it through an array, then restore the shuffled cards to the Set. section 26.1
  • Track whether cards are face up, remove cards when dealing, and count aces as either 1 or 11. section 26.1

Creating and dealing a deck

Create every suit-and-face combination, shuffle the deck, then deal an initial hand by popping two cards. Each popped card is marked face up and removed from the deck.

How Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond covers it

How deep it goes
Explains construction, shuffling, dealing, visibility, and ace scoring with code, but stops short of complete game rules.
Examples
Uses a 52-card deck, face-up tracking, initial two-card hands, and ace values of 1 or 11.
What it assumes
Assumes JavaScript collection and iteration knowledge while demonstrating Sets, Maps, objects, modules, and nested loops in context.
What you can do after
Builds a JavaScript card model that creates, shuffles, deals, reveals, and scores Blackjack cards.
How it connects
Connects cards with decks, suits, faces, shuffling, dealing, Blackjack, and hand scoring.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond. The section links point to the parts of the book it draws on.