Question
JAVASCRIPT : Need help to writing a basic simulation of how a BlackJack dealer draws cards Write a basic simulation of how a BlackJack dealer
JAVASCRIPT : Need help to writing a basic simulation of how a BlackJack dealer draws cards
Write a basic simulation of how a BlackJack dealer draws cards. Note: there is no user interaction here (no prompts or alerts, unless you're doing the Challenge portion), just output on the web page.
Assume there are multiple decks shuffled and in play, so don't have to worry about how many 8's could be drawn, for example. We also don't worry about suits or numbering face cards distinctly.
The dealer draws a card (from the shuffled decks, so it's random), always in the range of 1 to 10 (we'll say Aces are always low and face cards are worth 10). Use the random-number generation code we discussed in class.
The dealer keeps drawing cards (aka "hitting") until the cards total of 17 or greater.
After all the cards have been drawn, give a result that says that either the dealer went bust (totaled more than 21), or had a result less than that. Report the total and card count, too.
Here are example output from a "bust" run and a successful run:
"Bust" run:
Dealer drew a 3, now has 3 Dealer drew a 2, now has 5 Dealer drew a 7, now has 12 Dealer drew a 10, now has 22 Result: dealer went bust with 4 cards totaling 22
Successful run:
Dealer drew a 5, now has 5 Dealer drew a 7, now has 12 Dealer drew a 2, now has 14 Dealer drew a 1, now has 15 Dealer drew a 4, now has 19 Result: dealer ended with 5 cards totaling 19
Challenge Version
In addition to the instructions specified above:
Model a single player in addition to the dealer.
Assume, for now, that the player receives all cards first, then the dealer gets all cards.
Deal the player a starting card, then ask if they want another card.
Keep letting the player request cards until they wish to stop, hit 21, or go bust (with 22+).
You don't need to deal with who won, as the scenarios are a bit complex (i.e., bust vs. high score).
Below is an example of what the output might look like.
BlackJack
Player
Player drew a 8, now has 8 Player drew a 3, now has 11 Player drew a 2, now has 13 Player drew a 5, now has 18 Result: player ended with 4 cards totaling 18
Dealer
Dealer drew a 10, now has 10 Dealer drew a 3, now has 13 Dealer drew a 2, now has 15 Dealer drew a 1, now has 16 Dealer drew a 2, now has 18 Result: dealer ended with 5 cards totaling 18
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