Fundamentals (Paid)
  • 🚀Course Overview
  • Course Logistics
    • 🏫Course Methodology
      • 🧩Course Components
      • 💬Community Channels
      • 🎲Course Projects
    • 💻Required Hardware and Software
      • ☝️Required Software 1
      • ✌️Required Software 2
      • 👍Recommended Setup
    • 🗓️Schedule
    • 💡Tips and Tricks
      • 📒Coding Strategies
      • 🛠️Tooling Pro Tips
    • 🎓Post-Course
      • 🎓LinkedIn Certificates
      • 🚂Bootcamp Admission Criteria
  • 1: Introduction
    • 1.1: What is Coding?
    • 1.2: Web Browsers
    • 1.3: Command Line
    • Additional Resources 1
  • 2: Basic Data Manipulation
    • 2: Operators and Expressions
      • 2.1: Arithmetic Operators | Mathematical Expressions
      • 2.2: Assignment Operators | Variables
    • 2.3: Our First Program
    • Additional Resources 2
  • 3: Structuring and Debugging Code
    • 3.1: Functions
    • 3.2: Errors
    • Additional Resources 3
  • 4: Conditional Logic
    • 4.1: Intro to Logic
    • 4.2: Pseudo-Code, Boolean Or
    • 4.3: Boolean AND, NOT
    • 4.4: Input Validation
    • Additional Resources 4
  • 5: Managing State and Input Validation
    • 5.1: Program Lifecycle and State
    • 5.2: Program State for Game Modes
    • Additional Resources 5
  • 6: Arrays and Iteration
    • 6.1: Arrays
    • 6.2: Loops
    • 6.3: Loops with Arrays
    • Additional Resources 6
  • 7: Version Control
    • 7.1: Git
    • Additional Resources 7
  • 8: GitHub
    • 8.1: Intro to GitHub
    • 8.2: GitHub Fork and Clone
    • 8.3: GitHub Pull Request
    • 8.4: GitHub Repo Browsing
    • 8.5: Deployment
    • Additional Resources 8
  • 9: JavaScript Objects
    • 9.1: JavaScript Objects
    • 9.2: Card Deck Generation with Loops
  • 10: Advanced
    • 10.1 HTML
    • 10.2: CSS
    • 10.3: The Document Object Model
    • 10.4: DOM Manipulation
    • 10.5: Advanced Debugging with Sources Tab
  • 11: POST COURSE EXERCISES
    • DOM
    • Further Readings
  • In-Class Exercises
    • Day 2: Basic File and Data Manipulation
    • Day 3: Functions
    • Day 4: If Statements, Boolean Or, Boolean And
    • Day 5: Program State
    • Day 6: Scissors Paper Stone Redux
    • Day 7: Loops
    • Day 8: Arrays and Loops
    • Day 9: Beat That Redux
    • Day 10: Moar Cards / Chat Bot
    • Day 11: Blackjack Redux, DOM
  • Projects
    • Project 1: Scissors Paper Stone
      • Project 1: Scissors Paper Stone (Part 1)
      • Project 1: Scissors Paper Stone (Part 2)
    • Project 2: Beat That!
    • Project 3: Blackjack
  • Past Projects
    • Drawing With Emojis
    • Guess the Word
Powered by GitBook
On this page
  • Introduction
  • Past Projects
  • Setup
  • Base
  • Gameplay Description
  • General Tips
  • How to Prioritise Work
  • Walkthrough
  • Comfortable
  • Interface
  • More Comfortable
  • Hide Dealer's First Card
  • Additional HTML Elements
  • Additional Game Logic
  • Submit
  • Sharing
  • Setting the Share Link
  • Reference Solution
  1. Projects

Project 3: Blackjack

PreviousProject 2: Beat That!NextDrawing With Emojis

Last updated 8 months ago

Introduction

Implement a simplified version of Blackjack. If you're not familiar with Blackjack, refer to for game rules. Our simplified rules are the following. Please read all the requirements before starting it!

  1. There will be only two players. One human and one computer (for the Base solution).

  2. The computer will always be the dealer.

  3. Each player gets dealt two cards to start.

  4. The player goes first, and decides if they want to hit (draw a card) or stand (end their turn).

  5. The dealer has to hit if their hand is below 17.

  6. Each players' score is the total of their card ranks. Jacks/Queen/Kings are 10. Aces can be 1 or 11.

  7. The player who is closer to, but not above 21 wins the hand.

Past Projects

Take a look at some past project as references, and student-voted most-creative projects from previous Batches for inspiration :)

Setup

Base

Gameplay Description

The main function runs on each player's turn. The sequence of actions in the game might be the following.

  1. Deck is shuffled.

  2. User clicks Submit to deal cards.

  3. The cards are analysed for game winning conditions, e.g. Blackjack.

  4. The cards are displayed to the user.

  5. The user decides whether to hit or stand, using the submit button to submit their choice.

  6. The user's cards are analysed for winning or losing conditions.

  7. The computer decides to hit or stand automatically based on game rules.

  8. The game either ends or continues.

Note that for the main function to perform different logic on user input, for example when a player decides to hit or stand, we may wish to consider using a new game mode.

General Tips

  1. Creating helper functions can be a powerful way to refactor your code and keep it neat.

  2. Don't be afraid to throw away code, especially if you already know how you would write it better.

  3. Commit your code often, whenever you have a small working version. For example, each action listed above would be a commit. Make concise and precise commit messages so that you can reference your old changes later.

How to Prioritise Work

Given the above *final* action sequence to play a full game, how do we break these down into sub-features that we can work on (and verify they are working) one at a time? We want to work on features in small parts, but not have to redo any work as we expand the capability of the game, so we want to plan ahead to make sure we can start small and scaffold in the later features at the same time.

If you already have an effective strategy for creating your game, you can skip ahead. If you're not sure how to approach the game, try applying the following strategies to get started. The following are strategies for breaking down larger projects into smaller tasks to keep up progress, momentum, and motivation on the project. Please read to the end before starting.

First Version: Compare Initial Hands to Determine Winner

  1. Aim for a playable game. The essence of blackjack requires:

    1. Two players - a player and a dealer (computer).

    2. A deck of cards.

    3. A starting hand of 2 cards for each player.

    4. Comparing both hands and determining a winner. The possible scenarios are:

      • A tie. When both the player and dealer have the same total hand values - or if both draw Blackjack

      • A Blackjack win. When either player or dealer draw Blackjack.

      • A normal win. When neither draw Blackjack, the winner is decided by whomever has the higher hand total.

  2. Return appropriate messages. For example:

    Player hand: Ace of Hearts, King of Spades
    Dealer hand: 8 of Clubs, 8 of Spades
    Player wins by black jack!
  3. Test your code.

Second Version: Add Player Hit or Stand

  1. The player hitting or standing is different from the dealer hitting or standing. The rules state that the dealer hits or stands after all players are done, so let's work on the players hitting or standing first.

  2. The player hitting or standing is a new mode in the game that allows the player to enter their choice. Add the logic for when the player busts (has a total score of >21).

  3. Refactor your logic to wait until the player is done to evaluate the game-winning condition.

    • The player should not immediately lose if he busts - there is a possibility he will tie with the dealer if the dealer also busts.

  4. Test your code.

Third Version: Add Dealer Hit or Stand

  1. The rules state that the dealer hits after the player is done. After the player confirms they are done, add the logic for the dealer adding cards to their hand. This should happen before the winning condition.

  2. Test your code.

Fourth Version: Add Variable Ace Values

  1. Add logic to determine whether Aces should have value of 1 or 11 for a given hand.

    • For example, if a player draws cards in the following order:

      1. "Ace" and "2" (total 13)

      2. "4" (total 17)

      3. "Ace". (total 18)

      The total hand value should be 18, as only ONE of the aces will be counted as 11.

  2. Test your code.

Walkthrough

Comfortable

Interface

User Instructions

Make the game intuitive and fun to use by adding explicit instructions for each step of the game. "Wow, you're at 14 right now! Do you want to hit or stand? Type h for hit or s for stand."

Starting Instructions

<div id="output-div">
  Welcome to Kai's Cards! Click the submit button to get started!
</div>

Emoji

Use emoji for the card suits ♣️♠️♦️♥️and for the card names 2️⃣. Use more emoji in your game instructions and results. Get creative!

Images

You can add images to your game by including an HTML image tag in myOutputValue.

var myImage = '<img src="https://c.tenor.com/Hj2-u4VELREAAAAi/655.gif"/>';
myOutputValue = myOutputValue + myImage; // will display an image in the grey box

Image variable template: Fill in the COPIED_URL_OF_IMAGE with any image URL you find.

var myImage = '<img src="COPIED_URL_OF_IMAGE"/>';

Using images

  1. Right-click on an image and copy the url by selecting "Copy Image Address".

  2. Paste this value into your code as shown above.

Using your own images

Place an image file in your Git repository. Commit the image file and push your image to your GitHub repository.

For example you added an image called my-image.jpeg into your repository directory. Refer to it like the following:

var myImage = '<img src="/my-image.jpeg" />';
myOutputValue = myOutputValue + myImage; // will display an image in the grey box

Image variable template: Fill in the COPIED_RELATIVE_IMAGE_PATH with the image file name you uploaded to your repo.

var myImage = '<img src="/COPIED_RELATIVE_IMAGE_PATH"/>';

Colors

Fonts

More Comfortable

Hide Dealer's First Card

In most casinos, all cards are face-up except the dealer's first card. This injects a dimension of strategy into the game, as the player does not have perfect information to begin with. Edit your game logic such that the player is only told one of the dealer's first two cards.

Additional HTML Elements

Additional Game Logic

Try adding one or more additional game features (you can also have different versions with different features if implementing all features in one version is too complicated):

Betting

The player starts with 100 points. Each round the player wagers a number of points before their hand is dealt. Keep track of the player's points throughout the game.

Multiplayer

Enable multiple players to play against the dealer, where players can take turns. The game hides and shows relevant hand according to the turn.

Splits

Submit

  1. Please leave your name and section number in the title of the pull request.

  2. Please fill in the questionnaire in the pull request comments when you submit.

Sharing

The cloned BlackJack repo has built-in sharing code. When you share your project with friends on major platforms it will have a nice looking share image.

Setting the Share Link

Edit the index.html to match the GitHub Pages URL you created in the instructions above.

To have your share link properly link to your page, find your GitHub Pages URL:

Replace the url in the URL section of the meta tags in index.html:

<meta property="og:url" content="<PUT YOUR URL HERE>index.html">
<meta name="twitter:url" content="<PUT YOUR URL HERE>index.html">

Sharing text: Put your name and some fun text in the share!

<meta property="og:title" content="YOURNAME's BlackJack Game!">
<meta property="og:description" content="A fun card game I made myself! 😄💪🌈">
<meta name="twitter:title" content="YOURNAME's BlackJack Game!">
<meta name="twitter:description" content="A fun card game I made myself! 😄💪🌈">
<meta name="twitter:image" content="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/basics/basics-blackjack-share-small.jpeg">
<meta name="twitter:site" content="@rocketacademyco">
<meta name="twitter:creator" content="@rocketacademyco">

Reference Solution

Please only refer to the reference solution after you have attempted the project. Note that there are many ways to implement the project and the reference solution is only 1 way.

Rocket Academy does not endorse gambling. We chose Blackjack as a project because of its complex rules that help facilitate coding instruction.

Begin by forking the . Once forked, clone your fork of the repo and work on that copy.

Review

If you are still unsure how to start, or find yourself stuck for too long, Bryan can walk you through how to get to the Base solution. Please try to attempt the project once yourself before referencing the walkthrough, and do note that the video uses template code straight from . If you would like to follow along exactly, you can start with the used in the walkthrough.

The completed base version as per the walkthrough can be viewed !

Improve the look and feel of your game - if you did not attempt the Comfortable version of Beat That!, you can use the as a quick-start guide. If you have, feel free to move on, and add your own creative touches.

Add instructions on how to start the game by editing the index.html. Simply add your instructions into . These instructions will appear when the game loads and will be erased as soon as the user clicks the submit button.

Go to a site like for gifs (although any website with images will work)

Set your own custom colors in the CSS. Find the color values in index.html and change them. Use this tool to find the colors you want:

Find matching color sets using this design tool:

Set your own custom fonts:

Look ahead to to see how additional HTML elements can be referenced and manipulated; add a button for 'Hit' and 'Stand'.

Add hand-splitting functionality to the game. If the player has two of the same kind of card, they can choose to split and get dealt 2 new cards. Full splitting rules . Dealer is not allowed to split.

the commits in your local repo to GitHub.

to submit your assignment.

Facebook Share URL: line

Twitter Share URL: line

For Facebook / Slack / Whatsapp / Discord / Disco LMS Shares: edit lines in the index.html

For Twitter Shares: edit lines in the index.html

this video
Base
Comfortable 1
Comfortable 2
Super Comfortable
Wall St. Casino
MCU BlackJack
BlackJack 99
Kawaii BlackJack
Real Cards™ BlackJack
SouthPark Casino
Edwin's Casino
Cheok's Lounge
来玩·万辣
SouthPark Casino
Cat-sino
Simple and Green
90's Night
Coding Fundamentals Blackjack repo
Coding Strategies
10.2: Card Deck Generation
base code
here
line 134
tenor.com
https://www.w3schools.com/colors/colors_picker.asp
https://color.adobe.com/create/color-wheel
https://www.w3schools.com/css/css_font_google.asp
12.1 Browser Application with DOM
here
30
37
31 & 32
38-42
Base
Multiplayer
Blackjack Base Walkthrough
instructions there
Push
Create a pull request
How to Copy a website Image Address
Twitter Sharing Example