scrimba
Learn JavaScript
Blackjack
Add to the sum when newCard is clicked
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Add to the sum when newCard is clicked
AboutCommentsNotes
Add to the sum when newCard is clicked
Expand for more info
index.js
run
preview
console
let firstCard = 10
let secondCard = 4
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 cardsEl = document.getElementById("cards-el")

function startGame() {
cardsEl.textContent = "Cards: " + firstCard + " " + secondCard
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)

// 2. Add the new card to the sum variable

// 3. Call startGame()
}
Console
/index.html
-3:16