Skip to content

Commit b079e9a

Browse files
Initial commit
0 parents  commit b079e9a

File tree

10 files changed

+170
-0
lines changed

10 files changed

+170
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 justintsugranes
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Blackjack Game
2+
3+
Primitives and complex data types like:
4+
Arrays: push and pop
5+
Objects: key, value pairs
6+
Booleans
7+
8+
If else statements
9+
Comparison operators: &&
10+
Logical operators: ||
11+
12+
For loops
13+
14+
The Math object:
15+
Using Math.floor and Math.random to generate a random number
16+
17+
Returning values in functions

images/table.jpeg

7 KB
Loading

images/table.png

862 KB
Loading

index.css

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
body {
2+
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', Arial,
3+
sans-serif;
4+
background-image: url('images/table.png');
5+
background-size: cover;
6+
font-weight: bold;
7+
color: white;
8+
text-align: center;
9+
}
10+
11+
h1 {
12+
color: goldenrod;
13+
}
14+
15+
.main-container {
16+
display: flex;
17+
flex-direction: column;
18+
align-items: center;
19+
justify-content: center;
20+
}
21+
22+
#message-el {
23+
font-style: italic;
24+
}
25+
26+
#cards-el {
27+
border: 1px solid white;
28+
padding: 15px 15px 15px 15px;
29+
}
30+
31+
#sum-el {
32+
}
33+
34+
button {
35+
color: #016f32;
36+
width: 150px;
37+
background: goldenrod;
38+
padding-top: 5px;
39+
padding-bottom: 5px;
40+
font-weight: bold;
41+
border: none;
42+
border-radius: 2px;
43+
margin-bottom: 2px;
44+
margin-top: 2px;
45+
}

index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<html>
2+
<head>
3+
<link
4+
rel="stylesheet"
5+
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css"
6+
/>
7+
<link rel="stylesheet" href="index.css" />
8+
</head>
9+
<body>
10+
<div class="main-container">
11+
<h1>Blackjack</h1>
12+
<p id="player-el"></p>
13+
<p id="message-el">Want to play a round?</p>
14+
<p id="cards-el">Cards:</p>
15+
<p id="sum-el">Sum:</p>
16+
<button onclick="startGame()">START GAME</button>
17+
<button onclick="newCard()">NEW CARD</button>
18+
</div>
19+
<script src="index.js"></script>
20+
</body>
21+
</html>

index.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
let player = {
2+
name: 'Player',
3+
chips: 200,
4+
}
5+
6+
let cards = []
7+
let sum = 0
8+
let hasBlackJack = false
9+
let isAlive = false
10+
let message = ''
11+
let messageEl = document.getElementById('message-el')
12+
let sumEl = document.getElementById('sum-el')
13+
let cardsEl = document.getElementById('cards-el')
14+
let playerEl = document.getElementById('player-el')
15+
16+
playerEl.textContent = player.name + ': $' + player.chips
17+
18+
function getRandomCard() {
19+
let randomNumber = Math.floor(Math.random() * 13) + 1
20+
if (randomNumber > 10) {
21+
return 10
22+
} else if (randomNumber === 1) {
23+
return 11
24+
} else {
25+
return randomNumber
26+
}
27+
}
28+
29+
function startGame() {
30+
isAlive = true
31+
let firstCard = getRandomCard()
32+
let secondCard = getRandomCard()
33+
cards = [firstCard, secondCard]
34+
sum = firstCard + secondCard
35+
renderGame()
36+
}
37+
38+
function renderGame() {
39+
cardsEl.textContent = 'Cards: '
40+
for (let i = 0; i < cards.length; i++) {
41+
cardsEl.textContent += cards[i] + ' '
42+
}
43+
44+
sumEl.textContent = 'Sum: ' + sum
45+
if (sum <= 20) {
46+
message = 'Do you want to draw a new card?'
47+
} else if (sum === 21) {
48+
message = "You've got Blackjack!"
49+
hasBlackJack = true
50+
} else {
51+
message = "You're out of the game!"
52+
isAlive = false
53+
}
54+
messageEl.textContent = message
55+
}
56+
57+
function newCard() {
58+
if (isAlive === true && hasBlackJack === false) {
59+
let card = getRandomCard()
60+
sum += card
61+
cards.push(card)
62+
renderGame()
63+
}
64+
}

recap.jpg

110 KB
Loading

0 commit comments

Comments
 (0)