Created
March 17, 2018 18:37
-
-
Save fdjones/533f8e756a3a80b7feff0c130e0d7934 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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