-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
63 lines (52 loc) · 1.47 KB
/
script.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
let num1 = Math.floor(Math.random()*10)+2;
let num2 = Math.floor(Math.random()*10)+2;
let cards = [num1, num2];
let sum = num1 + num2;
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() {
let snd=new Audio("flipcard.mp3");
snd.play();
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) {
let snd=new Audio("win.mp3");
snd.play();
const jsConfetti = new JSConfetti()
jsConfetti.addConfetti(
{
confettiRadius: 10,
confettiNumber: 500,
}
)
message = "You've got Blackjack!"
hasBlackJack = true
} else {
let snd=new Audio("loose.mp3");
snd.play();
message = "You're out of the game!"
isAlive = false
}
messageEl.textContent = message
}
function drawNewCard() {
let snd=new Audio("newcard.mp3");
snd.play();
let card = Math.floor(Math.random()*10)+2;
sum += card
cards.push(card)
console.log(cards)
renderGame()
}