Javascript Blackjack Example

Posted By admin On 08/04/22
Javascript Blackjack Example Average ratng: 7,6/10 8776 reviews
  1. Cool Javascript Examples
  2. Examples Of Javascript Code
  3. Javascript Game Code Examples
  4. Free Javascript Code Examples

For my first JavaScript/jQuery project, I made a simple Blackjack game. However, I would like to have a more object oriented approach. I would truly appreciate it if someone can review my code and point out how I can make it more object oriented. I'm having trouble creating a Blackjack program to display in an HTML page using an external Javascript file. I don't need to label my cards, and I've created a dealer that will always be between 17-21 in score. I'm unsure of what parts of my code is completely wrong and what needs a bit of tweaking. This javascript game is another guessing game. If yo uare learning to make games in javascript this is a very simple game with example code. Enter the first 3 digits of your SSN and the script will tell you where you were born. Go ahead - see if JavaScript can tell you where you were born.

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

JavaScript story teller A JavaScript story teller that will produce a different story for each of your surfers, depending on his personal information. Mind Guesser: This script will tell what you are thinking! Mine Sweeper This is an incredible recreation of the Window's game 'Mine Sweeper' using JavaScript.

Javascript Blackjack ExampleExample

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

Javascript

The smallest game of Blackjack requires 2 people – a player and a 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.

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];

Cool Javascript Examples

// variable to choose a random card from the deck

Examples Of Javascript Code

Javascript blackjack example program

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

card_remove = card,

position = deck.indexOf(card);

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

Javascript Game Code Examples

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

console.warn(card)

Free Javascript Code Examples

Example

console.warn(deck)

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.