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
31 changes: 31 additions & 0 deletions Untitled-1.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("images/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;
}
12 changes: 10 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="Untitled-1">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="index.js"></script>
<title>BlackJack ♠️♥️♦️♣️</title>
</head>
<body>

</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 onclcick="startGame()">START GAME</button>
<button onclick="newCard()">NEW CARD</button>
<p id="player-el"></p>
<script src="index.js"></script>
</body>
</html>

73 changes: 66 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,70 @@
// 1. Create two variables, firstCard and secondCard.
// Set their values to a random number between 2-11

// 2. Create a variable, sum, and set it to the sum of the two cards
let player = {
name: "Per",
chips: 200
}

let firstCard = 6
let secondCard = 9

let sum = firstCard + secondCard
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")
let playerEl = document.getElementById("player-el")

console.log(sum)
playerEl.textContent = player.name + ": $" + player.chips

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

function startGame() {
isAlive = true
let firstCard = getRandomCard()
let secondCard = getRandomCard()
cards = [firstCard, secondCard]
sum = firstCard + secondCard
renderGame()

}

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 if(sum > 21) {
message = "You're out of the game!"
isAlive = false
}

messageEl.textContent = message
}


function newCard() {
if (isAlive === true && hasBlackJack === false) {
let card = getRandomCard()
sum += card
cards.push(card)
renderGame()
}
}