Skip to content

Instantly share code, notes, and snippets.

@ReinierC
Last active January 5, 2018 15:41
Show Gist options
  • Save ReinierC/e8cef82018ac058a86bd7733cefd10aa to your computer and use it in GitHub Desktop.
Save ReinierC/e8cef82018ac058a86bd7733cefd10aa to your computer and use it in GitHub Desktop.
blackjack card count

RC Logo

a card counting function.

It will receive a card parameter and increment or decrement the global count variable. the function will then return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative. The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.

var count = 0;
function cc(card) {
switch (card) {
case 2:
count+=1;
break;
case 3:
count+=1;
break;
case 4:
count+=1;
break;
case 5:
count+=1;
break;
case 6:
count+=1;
break;
case 7:
count+=0;
break;
case 8:
count+=0;
break;
case 9:
count+=0;
break;
case 10:
count-=1;
break;
case "J":
count-=1;
break;
case "Q":
count-=1;
break;
case "K":
count-=1;
break;
case "A":
count-=1;
break;
}
if (count <= 0) {
return (count) + " Hold";
} else {
return (count) + " Bet";}
}
// Note: Only the last will display
cc(7); cc(8); cc(3); cc(); cc();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment