Skip to content

Instantly share code, notes, and snippets.

@fdjones
Created March 17, 2018 18:37
Show Gist options
  • Save fdjones/533f8e756a3a80b7feff0c130e0d7934 to your computer and use it in GitHub Desktop.
Save fdjones/533f8e756a3a80b7feff0c130e0d7934 to your computer and use it in GitHub Desktop.
function Hand() {
this.cards = [];
this.score = function () {
var i;
var total = 0;
for (i = 0; i < this.cards.length; i++) {
if (this.cards[i].rank === "A") {
total++;
}
else if (this.cards[i].rank === "J" || this.cards[i].rank === "Q" ||
this.cards[i].rank === "K") {
total += 10;
}
else {
total += parseInt(this.cards[i].rank, 10);
}
}
// Now change aces to 11 if possible
for (i = 0; i < this.cards.length; i++) {
if (this.cards[i].rank === "A" && total <= 11) {
total += 10;
}
}
return total;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment