Javascript Blackjack Dealer

Looking for a new project in JavaScript that I have not done in Python, I got to thinking about arrays.

As JavaScript allows us to generate random numbers and store variables (see “Scissor, Paper, Stone”) it should allow me to also recreate the card game of Blackjack or 21. For more information on Blackjack please see: https://en.wikipedia.org/wiki/Blackjack

In this JavaScript code challenge, you're given an array of cards. You have to figure out whether the hand is above/below/at blackjack and the highest card. If the dealer has a 6 or lower showing, and if the casino allows it, you’ll double down on this hand. If the casino doesn’t allow you to double down on a soft 18, you’ll stand instead. If the dealer has a 7 or 8, you’ll stand on a soft 18. If the dealer has a 9, 10, or ace showing, you’ll hit a soft 18. I'm working on a JavaScript blackjack game for a class of mine. So far I have a method to create stacks for the deck, the player and the dealer. Another creates the deck, one creates each card as an object. Another shuffles, one deals out cards from the deck stack. BlackJack Application with JavaScript by@ethan.jarrell. And one for STAND, which will check the values, and draw a card for the dealer if needed. At minimum, that.

The smallest game of Blackjack requires 2 people – a player and a dealer.

Javascript blackjack dealer portalJavascript Blackjack Dealer

The objective of Blackjack is for the player to either score 21 with 2 cards, or get a higher score than the dealer without going over 21. If the player goes over 21 then they lose. If the dealer goes over 21 then the banker loses.

The dealer is going to be controlled by the computer.

Javascript Blackjack Dealer Login

I’m going to use one deck of cards (52 cards). The 52 cards are split into 4 suites (Hearts, Diamonds, Spades, Clubs) with each suite containing 13 cards:

Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King

For this version of Blackjack I’m going to define an Ace as having the value of 1, and the Jack, Queen, King as having the value of 11.

So each suite now has;

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 11

The values can be stored in an array, which we can call “deck”:

// variable to hold the deck of 52 cards

var deck = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11];

We then need JavaScript to randomly choose a card and remove the card from the possible cards that can be played.

// geektechstuff

// BlackJack

// variable to hold the deck of 52 cards

var deck = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11];

// variable to choose a random card from the deck

var card = deck[Math.floor(Math.random()*deck.length)],

card_remove = card,

position = deck.indexOf(card);

Javascript Blackjack Dealer Log

if (~position) deck.splice(position, 1);

// checking that a card is picked and that it is removed from deck

console.warn(card)

console.warn(deck)

Javascript Blackjack Dealers

Next up I will need to look at storing the card values in the players hand or the dealers hand and checking if the values have gone over 21.