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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!