Question
Write a JavaScript function to compute and return a persons score in the game of 21. Your function must have this header function twentyOne(hand) {
Write a JavaScript function to compute and return a persons score in the game of 21. Your function must have this header
function twentyOne(hand) {
The parameter hand is an array that contains integers between 1 and 10, inclusive. The length of the hand array will vary. Your function must add all the integers in the array. If the sum is greater than 21, your function must return the string "bust", otherwise your function must return the sum. For example, if your function were called like this:
var cards = [8, 3, 6]; var score = twentyOne(cards);
your function would return the number 17. If your function were called like this:
var cards = [10, 4, 2, 7]; var score = twentyOne(cards);
your function would return the string "bust".
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