4. Write a JavaScript function to compute and return a person\'s score in the ga
ID: 3704278 • Letter: 4
Question
4. Write a JavaScript function to compute and return a person's 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-[1e, 4, 2, 71; var score-twentyOne (cards); your function would return the string "bust".Explanation / Answer
function twentyOne(hand) { var total = 0; for(var i = 0; i 21) { return "bust"; } else { return total; } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.