Skip to content
Advertisement

problem counting the cards in a blackjack game

i made a blackjack game and i’m having problems counting my cards with the aces. Can someone help me clean my code

JavaScript

i have those exemple:

player1

[[‘1’, ‘D’], [’11’, ‘C’], [’11’, ‘D’], [‘1’, ‘H’]]

Do you want to hit or stand? (h/s)

total = 21

player1

[[‘1’, ‘D’], [’10’, ‘D’], [’11’, ‘H’], [‘1’, ‘H’]]

Do you want to hit or stand? (h/s)

total = 21

Advertisement

Answer

Something like this:

JavaScript

And, by the way, any card game that shows 1, 11, 12 and 13 instead of A, J, Q, K is not worth playing. Since you’re storing the cards as strings anyway, why not just store the familiar letters? It would take very minor changes to your code, and the user experience would be much better:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement