Question
https://courses.engr.illinois.edu/cs105/labs/5/index.php Introduction This week we introduced the concept of an Array . In lab you will combine your knowledge of loops, arrays, and strings to
https://courses.engr.illinois.edu/cs105/labs/5/index.php
Introduction
This week we introduced the concept of an Array. In lab you will combine your knowledge of loops, arrays, and strings to complete a classic game of Blackjack.
Download the Lab
To get started, first download the ZIP file for Lab 5 here: https://courses.engr.illinois.edu/cs105/labs/5/cs105sp16lab5.zip
About Blackjack
Blackjack (sometimes called twenty-one) is played with a standard deck of playing cards: fifty-two cards divided up into four suits (clubs, diamonds, hearts, and spades) each with thirteen ranks (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, and K).
Lab Activity
In this lab, our game of blackjack will have only two players: a player and a dealer. We have already provided you with a base set of code to allow you to play as the player; you will need to program the code to determine if the dealer should take another card. Luckily, the dealer follows a very simple set of rules:
- If the dealer has 16 or fewer points, the dealer must take another card ("hit")
- If the dealer has 17 or more points, the dealer must not take another card ("stand")
The goal of a game of blackjack is to have a hand that has as close to 21 points, without going over. In standard blackjack, an ace (rank "A") is worth either 1 or 11 points. For simplicity, we will consider all aces to be worth only one point. Beyond that, the cards 2-10 are worth the rank in point value. Jacks (J), Queens (Q), and Kings (K) are each worth 10 points. For blackjack, the suit of the card is irrelevant.
Completing the Lab
Understanding the Dealer Function
Inside the provided code, you will find lab5.js which contains the one function that you must complete: dealerHit. The one and only parameter to the dealerHit function, hand, is an array of strings that represents the dealer's current hand. Each string within the array is formatted to represent one of the 52 possible cards and is formatted in the following way:
This results in a String representing each card. For example, "H6" is the six (6) of hearts (H), "C4" represents the four of clubs, "SQ" represents the queen of spades, and "D10" represents the ten of diamonds.
Since hand is an array of these strings, it will be necessary to count the total number of points across all of the cards in the hand.
The function should return true when the dealer should "hit" (to take another card) and false when the dealer should "stand". The values of true and false are Boolean in type and are not Strings, they do not get quotes.
Programming the Dealer Function
As part of programming dealerHit, there are two challenges to overcome:
You must examine each card, which means you will need to run the same code multiple times by using a loop.
You must find each card's rank, which is stored as part of a String. How do you get a character at a specific location in a string?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started