Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions blackjack-game-main/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# BlackJack-Game Website

## Description
This is a simple web application that helps in playing blackjack. It was created by following a tutorial from FreeCodeCamp.

## Features
- **Start a game**: Allows users to pick a card.
- **Get a new card**: Users can get a new card and if the total exceeds 21 they are out of the game.
- **Reset functionality**: Resets the count back to zero.

## How to Use
1. Open the website.
2. Click the 'Start Game' button to start the game and get a card.
3. Use the 'New Card' button to get a new card.
4. If the total points exceed 21 the user is out of the game.

## Built With
- HTML
- CSS
- JavaScript

## Acknowledgements
- This project was built by following a FreeCodeCamp tutorial.

## Author
- Anant Jain
18 changes: 18 additions & 0 deletions blackjack-game-main/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blackjack game</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Blackjack</h1>
<p id="message-el">Want to play a round?</p>
<p id="cards-el">Cards:</p>
<p id="sum-el">Sum:</p>
<button onclick="startGame()">START GAME</button>
<button onclick="newCard()">NEW CARD</button>
<script src="script.js"></script>
</body>
</html>
58 changes: 58 additions & 0 deletions blackjack-game-main/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
let cards=[];
let sum = 0;
let hasBlackJack = false;
let isAlive = false;
let message = "";
let messageEl = document.getElementById("message-el");
let sumEl = document.getElementById("sum-el");
let cardsEl = document.getElementById("cards-el");


function getRandomCard(){
let randomNumber= Math.floor(Math.random()*13)+1;
if(randomNumber===1){
return 11;
}
else if(randomNumber>10){
return 10;
}
else{
return randomNumber;
}
}


function renderGame() {
cardsEl.textContent = "Cards: ";
for (let i=0;i<cards.length;i++){
cardsEl.textContent+=cards[i]+" ";
}
sumEl.textContent = "Sum: " + sum;
if (sum <= 20) {
message = "Do you want to draw a new card?";
} else if (sum === 21) {
message = "You've got Blackjack!";
hasBlackJack = true;
} else {
message = "You're out of the game!";
isAlive = false;
}
messageEl.textContent = message;
}
function startGame(){
isAlive = true;
let firstCard = getRandomCard();
let secondCard = getRandomCard();
cards = [firstCard, secondCard];
sum = firstCard + secondCard;
renderGame();
}

function newCard() {
if(isAlive===true&&hasBlackJack===false){
let card=getRandomCard();
cards.push(card);
sum+=card;
renderGame();
}
}
31 changes: 31 additions & 0 deletions blackjack-game-main/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
body {
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', Arial, sans-serif;
background-image: url("table.png");
background-size: cover;
font-weight: bold;
color: white;
text-align: center;
}

h1 {
color: goldenrod;
}

#message-el {
font-style: italic;
}


button {
color: #016f32;
width: 150px;
background: goldenrod;
padding-top: 5px;
padding-bottom: 5px;
font-weight: bold;
border: none;
border-radius: 2px;
margin-bottom: 2px;
margin-top: 2px;
cursor: pointer;
}
Binary file added blackjack-game-main/table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.