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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
# Rocket Academy Coding Basics: Blackjack

## Overview
This project is a simple implementation of a card game inspired by Blackjack, built as part of Rocket Academy's Coding Fundamentals course. The game allows the player to compete against the computer by drawing cards, with the goal of reaching as close to 21 points as possible without exceeding it.

## How to Play
1. Click the "Play" button to start the game. Both the player and the computer will receive two cards each.
2. The scores are calculated based on the values of the cards. If either player has a score of 21 (Blackjack), the game ends immediately, and the winner is declared.
3. If neither player has a Blackjack, the player can choose to either:
- **Hit**: Draw another card to increase their score.
- **Stand**: End their turn and let the computer play.
4. The computer will continue drawing cards until its score is 17 or more.
5. The player and computer scores are compared, and the winner is determined based on who is closer to 21 without exceeding it.
6. The player can restart the game at any time by clicking the "Restart" button.

## Instructions
1. Clone the repository.
2. Open the index.html file in a browser.
3. Start playing by clicking the "Play" button.

## Game Screenshot
![Game Screenshot](https://github.com/user-attachments/assets/6d508fa3-fa13-4147-b461-baf3d65d9998)
![Game Screenshot 2](https://github.com/user-attachments/assets/52aa51c6-f2aa-4548-9975-6e5478591275)
Binary file added images/__MACOSX/images/._aceOfClubs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._aceOfDiamonds.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._aceOfHearts.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._aceOfSpades.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._chip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._eightOfClubs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._eightOfDiamonds.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._eightOfHearts.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._eightOfSpades.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._fiveOfClubs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._fiveOfDiamonds.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._fiveOfHearts.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._fiveOfSpades.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._fourOfClubs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._fourOfDiamonds.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._fourOfHearts.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._fourOfSpades.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._jackOfClubs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._jackOfDiamonds.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._jackOfHearts.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._jackOfSpades.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._kingOfDiamonds.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._kingOfHearts.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._kingOfSpades.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._kingofClubs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/__MACOSX/images/._nineOfClubs.jpg
Binary file added images/__MACOSX/images/._nineOfDiamonds.jpg
Binary file added images/__MACOSX/images/._nineOfHearts.jpg
Binary file added images/__MACOSX/images/._nineOfSpades.jpg
Binary file added images/__MACOSX/images/._queenOfClubs.jpg
Binary file added images/__MACOSX/images/._queenOfDiamonds.jpg
Binary file added images/__MACOSX/images/._queenOfHearts.jpg
Binary file added images/__MACOSX/images/._queenOfSpades.jpg
Binary file added images/__MACOSX/images/._sevenOfClubs.jpg
Binary file added images/__MACOSX/images/._sevenOfDiamonds.jpg
Binary file added images/__MACOSX/images/._sevenOfHearts.jpg
Binary file added images/__MACOSX/images/._sevenOfSpades.jpg
Binary file added images/__MACOSX/images/._sixOfClubs.jpg
Binary file added images/__MACOSX/images/._sixOfDiamonds.jpg
Binary file added images/__MACOSX/images/._sixOfHearts.jpg
Binary file added images/__MACOSX/images/._sixOfSpades.jpg
Binary file added images/__MACOSX/images/._tenOfClubs.jpg
Binary file added images/__MACOSX/images/._tenOfDiamonds.jpg
Binary file added images/__MACOSX/images/._tenOfHearts.jpg
Binary file added images/__MACOSX/images/._tenOfSpades.jpg
Binary file added images/__MACOSX/images/._threeOfClubs.jpg
Binary file added images/__MACOSX/images/._threeOfDiamonds.jpg
Binary file added images/__MACOSX/images/._threeOfHearts.jpg
Binary file added images/__MACOSX/images/._threeOfSpades.jpg
Binary file added images/__MACOSX/images/._twoOfClubs.jpg
Binary file added images/__MACOSX/images/._twoOfDiamonds.jpg
Binary file added images/__MACOSX/images/._twoOfHearts.jpg
Binary file added images/__MACOSX/images/._twoOfSpades.jpg
Binary file added images/aceOfClubs.jpg
Binary file added images/aceOfDiamonds.jpg
Binary file added images/aceOfHearts.jpg
Binary file added images/aceOfSpades.jpg
Binary file added images/chip.png
Binary file added images/eightOfClubs.jpg
Binary file added images/eightOfDiamonds.jpg
Binary file added images/eightOfHearts.jpg
Binary file added images/eightOfSpades.jpg
Binary file added images/fiveOfClubs.jpg
Binary file added images/fiveOfDiamonds.jpg
Binary file added images/fiveOfHearts.jpg
Binary file added images/fiveOfSpades.jpg
Binary file added images/fourOfClubs.jpg
Binary file added images/fourOfDiamonds.jpg
Binary file added images/fourOfHearts.jpg
Binary file added images/fourOfSpades.jpg
Binary file added images/images/aceOfClubs.jpg
Binary file added images/images/aceOfDiamonds.jpg
Binary file added images/images/aceOfHearts.jpg
Binary file added images/images/aceOfSpades.jpg
Binary file added images/images/chip.png
Binary file added images/images/eightOfClubs.jpg
Binary file added images/images/eightOfDiamonds.jpg
Binary file added images/images/eightOfHearts.jpg
Binary file added images/images/eightOfSpades.jpg
Binary file added images/images/fiveOfClubs.jpg
Binary file added images/images/fiveOfDiamonds.jpg
Binary file added images/images/fiveOfHearts.jpg
Binary file added images/images/fiveOfSpades.jpg
Binary file added images/images/fourOfClubs.jpg
Binary file added images/images/fourOfDiamonds.jpg
Binary file added images/images/fourOfHearts.jpg
Binary file added images/images/fourOfSpades.jpg
Binary file added images/images/jackOfClubs.jpg
Binary file added images/images/jackOfDiamonds.jpg
Binary file added images/images/jackOfHearts.jpg
Binary file added images/images/jackOfSpades.jpg
Binary file added images/images/kingOfDiamonds.jpg
Binary file added images/images/kingOfHearts.jpg
Binary file added images/images/kingOfSpades.jpg
Binary file added images/images/kingofClubs.jpg
Binary file added images/images/nineOfClubs.jpg
Binary file added images/images/nineOfDiamonds.jpg
Binary file added images/images/nineOfHearts.jpg
Binary file added images/images/nineOfSpades.jpg
Binary file added images/images/queenOfClubs.jpg
Binary file added images/images/queenOfDiamonds.jpg
Binary file added images/images/queenOfHearts.jpg
Binary file added images/images/queenOfSpades.jpg
Binary file added images/images/sevenOfClubs.jpg
Binary file added images/images/sevenOfDiamonds.jpg
Binary file added images/images/sevenOfHearts.jpg
Binary file added images/images/sevenOfSpades.jpg
Binary file added images/images/sixOfClubs.jpg
Binary file added images/images/sixOfDiamonds.jpg
Binary file added images/images/sixOfHearts.jpg
Binary file added images/images/sixOfSpades.jpg
Binary file added images/images/tenOfClubs.jpg
Binary file added images/images/tenOfDiamonds.jpg
Binary file added images/images/tenOfHearts.jpg
Binary file added images/images/tenOfSpades.jpg
Binary file added images/images/threeOfClubs.jpg
Binary file added images/images/threeOfDiamonds.jpg
Binary file added images/images/threeOfHearts.jpg
Binary file added images/images/threeOfSpades.jpg
Binary file added images/images/twoOfClubs.jpg
Binary file added images/images/twoOfDiamonds.jpg
Binary file added images/images/twoOfHearts.jpg
Binary file added images/images/twoOfSpades.jpg
Binary file added images/jackOfClubs.jpg
Binary file added images/jackOfDiamonds.jpg
Binary file added images/jackOfHearts.jpg
Binary file added images/jackOfSpades.jpg
Binary file added images/kingOfDiamonds.jpg
Binary file added images/kingOfHearts.jpg
Binary file added images/kingOfSpades.jpg
Binary file added images/kingofClubs.jpg
Binary file added images/nineOfClubs.jpg
Binary file added images/nineOfDiamonds.jpg
Binary file added images/nineOfHearts.jpg
Binary file added images/nineOfSpades.jpg
Binary file added images/queenOfClubs.jpg
Binary file added images/queenOfDiamonds.jpg
Binary file added images/queenOfHearts.jpg
Binary file added images/queenOfSpades.jpg
Binary file added images/sevenOfClubs.jpg
Binary file added images/sevenOfDiamonds.jpg
Binary file added images/sevenOfHearts.jpg
Binary file added images/sevenOfSpades.jpg
Binary file added images/sixOfClubs.jpg
Binary file added images/sixOfDiamonds.jpg
Binary file added images/sixOfHearts.jpg
Binary file added images/sixOfSpades.jpg
Binary file added images/tenOfClubs.jpg
Binary file added images/tenOfDiamonds.jpg
Binary file added images/tenOfHearts.jpg
Binary file added images/tenOfSpades.jpg
Binary file added images/threeOfClubs.jpg
Binary file added images/threeOfDiamonds.jpg
Binary file added images/threeOfHearts.jpg
Binary file added images/threeOfSpades.jpg
Binary file added images/twoOfClubs.jpg
Binary file added images/twoOfDiamonds.jpg
Binary file added images/twoOfHearts.jpg
Binary file added images/twoOfSpades.jpg
265 changes: 149 additions & 116 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -8,148 +7,182 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />

<!-- Favicon configuration -->
<link rel="apple-touch-icon" sizes="180x180" href="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/all/favicons/apple-touch-icon.png?v=2">
<link rel="icon" type="image/png" sizes="32x32" href="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/all/favicons/favicon-32x32.png?v=2">
<link rel="icon" type="image/png" sizes="16x16" href="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/all/favicons/favicon-16x16.png?v=2">
<link rel="manifest" href="/site.webmanifest?v=2">
<link rel="mask-icon" href="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/all/favicons/safari-pinned-tab.svg?v=2" color="#e73c3e">
<link rel="shortcut icon" href="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/all/favicons/favicon.ico?v=2">
<meta name="apple-mobile-web-app-title" content="Rocket Academy">
<meta name="application-name" content="Rocket Academy">
<meta name="msapplication-TileColor" content="#2b5797">
<meta name="theme-color" content="#ffffff">
<link
rel="apple-touch-icon"
sizes="180x180"
href="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/all/favicons/apple-touch-icon.png?v=2"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/all/favicons/favicon-32x32.png?v=2"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/all/favicons/favicon-16x16.png?v=2"
/>
<link rel="manifest" href="/site.webmanifest?v=2" />
<link
rel="mask-icon"
href="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/all/favicons/safari-pinned-tab.svg?v=2"
color="#e73c3e"
/>
<link
rel="shortcut icon"
href="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/all/favicons/favicon.ico?v=2"
/>
<meta name="apple-mobile-web-app-title" content="Rocket Academy" />
<meta name="application-name" content="Rocket Academy" />
<meta name="msapplication-TileColor" content="#2b5797" />
<meta name="theme-color" content="#ffffff" />

<!-- sharing configuration -->
<!-- Primary Meta Tags -->
<title>Blackjack - Basics - Rocket Academy</title>
<meta name="title" content="YOURNAME's BlackJack Game!">
<meta name="description" content="A fun card game I made myself! 😄💪🌈">
<meta name="title" content="YOURNAME's BlackJack Game!" />
<meta name="description" content="A fun card game I made myself! 😄💪🌈" />

<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://rocketacademy.github.io/basics-blackjack/index.html">
<meta property="og:title" content="YOURNAME's BlackJack Game!">
<meta property="og:description" content="A fun card game I made myself! 😄💪🌈">
<meta property="og:image" content="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/basics/basics-blackjack-share-small.jpeg">
<meta property="og:type" content="website" />
<meta
property="og:url"
content="https://rocketacademy.github.io/basics-blackjack/index.html"
/>
<meta property="og:title" content="YOURNAME's BlackJack Game!" />
<meta
property="og:description"
content="A fun card game I made myself! 😄💪🌈"
/>
<meta
property="og:image"
content="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/basics/basics-blackjack-share-small.jpeg"
/>

<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:url" content="https://rocketacademy.github.io/basics-blackjack/index.html">
<meta name="twitter:title" content="YOURNAME's BlackJack Game!">
<meta name="twitter:description" content="A fun card game I made myself! 😄💪🌈">
<meta name="twitter:image" content="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/basics/basics-blackjack-share-small.jpeg">
<meta name="twitter:site" content="@rocketacademyco">
<meta name="twitter:creator" content="@rocketacademyco">
<meta name="twitter:card" content="summary_large_image" />
<meta
name="twitter:url"
content="https://rocketacademy.github.io/basics-blackjack/index.html"
/>
<meta name="twitter:title" content="YOURNAME's BlackJack Game!" />
<meta
name="twitter:description"
content="A fun card game I made myself! 😄💪🌈"
/>
<meta
name="twitter:image"
content="https://ra-web-files.s3.ap-southeast-1.amazonaws.com/basics/basics-blackjack-share-small.jpeg"
/>
<meta name="twitter:site" content="@rocketacademyco" />
<meta name="twitter:creator" content="@rocketacademyco" />

<!-- fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans">
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Open+Sans"
/>

<!-- CSS -->
<style>
* {
box-sizing: border-box;
#table {
display: flex;
justify-content: space-evenly;
}

body {
font-family: 'Open Sans', sans-serif;
margin-left: 30px;
margin-right: 30px;
background-color:white;
color: black; /* sets the font color */
background-image: url(""); /* The image used */
background-position: center; /* Center the image */
background-repeat: no-repeat; /* Do not repeat the image */
background-size: cover; /* Resize the background image to cover the entire container */
.player {
border: 1px solid rgb(158, 112, 52);
border-radius: 10px;
padding: 10px;
margin: 10px;
width: 50%;
height: 300px;
}

#output-div img{
display:block;
max-width:100%;
max-height:200px;
}
.header {
text-align: center;
font-size: 1.1rem;
margin-bottom: 3rem;
}

#container {
background-color: pink;
margin: 40px auto;
max-width: 800px;
padding: 38px 31px;
}

input {
font-size: 21px;
line-height: 33px;
margin: 0 0 23px 0;
padding: 0 9px;
width: 100%;
#buttons {
display: flex;
justify-content: center;
}

button {
font-size: 21px;
line-height: 33px;
margin: 0 0 23px 0;
padding: 0 6px;
}
background-color: bisque;
border: none;
color: black;
font-family: cursive;
padding: 15px 32px;
text-align: center;
text-decoration: none;

#output-div {
background-color: lightgrey;
margin: 20px auto;
padding: 20px;
width: 100%;
font-size: 16px;
margin: 6px 2px 4px 10px;
cursor: pointer;
border-radius: 10px;
width: 140px;
}

.logo-img {
height: 49px;
position: relative;
top: 22px;
.p-card,
.c-card {
width: 170px;
}

/* increase header font size on wider screens */
@media screen and (min-width: 600px) {
.header {
font-size: 2rem;
}
#output {
height: 110px;
font-family: cursive;
font-size: large;
text-align: center;
}
</style>

</head>

<body>
<h1 class="header">
<img class="logo-img" src="https://firebasestorage.googleapis.com/v0/b/ftbc11-sample.appspot.com/o/images%2F1-PRIMARY_CRIMSON.png?alt=media&token=ce9e8333-2a45-44be-adb2-1f1bf054adf7" />
Rocket Academy
<img class="logo-img" src="https://firebasestorage.googleapis.com/v0/b/ftbc11-sample.appspot.com/o/images%2F1-PRIMARY_CRIMSON.png?alt=media&token=ce9e8333-2a45-44be-adb2-1f1bf054adf7" />
</h1>
<h1 class="header">♣️ Basics - Blackjack ♠️</h1>
<div id="container">
<p>Input:</p>
<input id="input-field" />
<br />
<button id="submit-button">Submit</button>
<p>Output:</p>
<div id="output-div"></div>
<h1 style="text-align: center; color: chocolate">BlackJack Game</h1>
<h3
style="text-align: center; color: rgb(158, 112, 52); font-family: cursive"
>
Hello, welcome to the BlackJack Game. <br />
Please click the "Play" button to start the game.
</h3>
<div id="table">
<div class="player">
<p
style="
text-align: center;
color: chocolate;
font-family: cursive;
font-size: larger;
"
>
Computer
</p>
<img class="c-card" id="card1" src="" alt="" />
<img class="c-card" id="card2" src="" alt="" />
<img class="c-card" id="card3" src="" alt="" />
<img class="c-card" id="card4" src="" alt="" />
<img class="c-card" id="card5" src="" alt="" />
</div>
<div class="player">
<p
style="
text-align: center;
color: chocolate;
font-family: cursive;
font-size: larger;
"
>
Player
</p>
<img class="p-card" id="card1" src="" alt="" />
<img class="p-card" id="card2" src="" alt="" />
<img class="p-card" id="card3" src="" alt="" />
<img class="p-card" id="card4" src="" alt="" />
<img class="p-card" id="card5" src="" alt="" />
</div>
</div>
<p id="output">Game Result</p>
<div id="buttons">
<button id="play-button">Play</button>
<button id="hit-button">Hit</button>
<button id="stand-button">Stand</button>
<button id="restart-button">Restart</button>
</div>
<!-- Import program logic -->
<script src="script.js"></script>
<!-- Define button click functionality -->
<script>
var button = document.querySelector("#submit-button");
button.addEventListener("click", function () {
// Set result to input value
var input = document.querySelector("#input-field");
var result = main(input.value);

// Display result in output element
var output = document.querySelector("#output-div");
output.innerHTML = result;

// Reset input value
input.value = "";
});
</script>
</body>
</html>
Loading