Skip to content

Instantly share code, notes, and snippets.

@hodbby
Created June 13, 2012 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hodbby/2922681 to your computer and use it in GitHub Desktop.
Save hodbby/2922681 to your computer and use it in GitHub Desktop.
Blackjack-1
<html>
<head><title>Blackjack</title></head>
<body>
<script type="text/javascript">
document.write ("This is Balckjack game.</br>");
document.write ("The points are as follow:</br>");
document.write ("Ace(1) = 11.</br>");
document.write ("King(12), Queen(11) and Prince(10) = 10.</br>");
document.write ("The rest by their own number values.</br></br>");
// Our deal function will return a random card
var deal = function() {
card = Math.floor(Math.random()*12+1);
return card;
};
// Deal out our first hand
var card1 = deal();
var card2 = deal();
// This function takes a card as a parameter and returns the value of that card
var getValue = function(card) {
// if its a face card, number should be set to 10
if( (card % 13 === 0) || (card % 13 === 12) || (card % 13 === 11) ) return 10;
// What if it's an ace?
if (card % 13 === 1) return 11;
// Otherwise, we just want its number value
else return card % 13;
}
// Score the hand
function score() {
return getValue(card1) + getValue(card2);
}
document.write("You have cards " + card1 + " and " + card2 + " which is a score of " + score(card1, card2));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment