-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (38 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
let firstCard = 10
let secondCard = 10
let cards = [firstCard, secondCard] //array -order of items
let sum = firstCard + secondCard
let hasBlackJack = false
let isAlive = true
let message = ""
let messageEl = document.getElementById("message-el")
let sumEl = document.getElementById("sum-el")
let cardEl = document.getElementById("cards-el")
// Create a new function called startGame() that calls renderGame()
function startGame() {
renderGame()
}
function renderGame() {
cardEl.textContent = "Cards: " + cards[0] + " " + cards[1]
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 newCard() {
console.log("Drawing a new card from the deck!")
// 1. Create a card variable, and hard code its value to a number (2-11)
let card = 7
// 2. Add the new card to the sum variable
sum += card
// 3. Call startGame()
cards.push(card)
renderGame()
}