"Black Jack"
Bootstrap 4.1.1 Snippet by Dom-inus

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <!DOCTYPE html> <html> <title>Welcome to Blackjack</title> <head> </head> <body> <div> <p>Welcome to our Blackjack Table!</p> <p id="PlayerScore">Your Score is: </p> <p id="DealerScore">Dealer's Score is: </p> </div> </body> </html>
var PlayerScore = 0; var DealerScore = 0; var Winner = "Nobody"; var AskAgain = true; function random(maxValue) { return Math.floor(Math.random() * maxValue) + 1; } function pickSuit() { suit = random(4); if(suit == 1) return "Spades"; if(suit == 2) return "Clubs"; if(suit == 3) return "Diamonds"; return "Hearts"; } function cardName(card) { if(card == 1) return "Ace"; if(card == 11) return "Jack"; if(card == 12) return "Queen"; if(card == 13) return "King"; return ("" + card); } function cardValue(card) { if(card == 1) return 11; if(card > 10) return 10; return card; } function PickACard(strWho) { card = random(13); suit = pickSuit(); alert(strWho + " picked the " + cardName(card) + " of " + suit); return cardValue(card); } function Dealer() { while(DealerScore < 17) { DealerScore = DealerScore + PickACard("Dealer"); } } function User() { PlayerScore = PlayerScore + PickACard("You"); } function LookAtHands(Winner) { if(DealerScore > 21) { alert("House busts! You win!"); Winner = "You"; } else if((PlayerScore > DealerScore) && (PlayerScore <= 21)) { alert("You win!"); Winner = "You"; } else if(PlayerScore == DealerScore) { alert("Push!"); Winner = "Tie"; } else { alert("House wins!"); Winner = "House"; } } Dealer(); alert("Dealer's score is: " + DealerScore); document.getElementById('DealerScore').innerHTML = DealerScore; User(); alert("Your score is: " + PlayerScore); document.getElementById("DealerScore").innerHTML = "Dealer's score is: " + DealerScore; while (AskAgain == true ) { var answer = confirm("Do you want to draw a card?") if (answer == true) { User(); alert("Your score is: " + PlayerScore); document.getElementById("PlayerScore").innerHTML = "Your score is: " + PlayerScore; if (PlayerScore < 21) {AskAgain = true;} else {AskAgain = false;} } else { AskAgain = false; } } LookAtHands();

Related: See More


Questions / Comments: