-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
97 lines (64 loc) · 2.23 KB
/
Copy pathscript.js
File metadata and controls
97 lines (64 loc) · 2.23 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
let firstCard = getRandomCard()
let secondCard = getRandomCard()
let sum = firstCard + secondCard
let cards = [firstCard, secondCard]
let hasBlackJack = false
let isAlive = true
let newCard = getRandomCard()
let cardsEl = document.getElementById("cards-p")
let message = ""
let player_el = document.getElementById("player")
let player_info = {
name: "somil",
chips: 175
}
player_el.textContent = ("Name: " + player_info.name + " Chips: " + player_info.chips)
// let randomNumber = Math.floor(Math.random() * 9)
function getRandomCard() {
let randomNumber = Math.floor(Math.random()*13) + 1
if (randomNumber == 1) {
return 11
} else if (randomNumber == 11 || randomNumber == 12 || randomNumber == 13) {
return 10
} else {
return randomNumber
}
}
function start() {
render_game()
}
function render_game() {
cardsEl.textContent = "Cards: "
if (sum <= 20) {
message = "Do you want to draw a new card"
document.getElementById("q-heading").textContent = message
document.getElementById("sum-p").textContent = "Sum: " + sum
// document.getElementById("cards-p").textContent = "Cards: " + cards[0] + " and " + cards[1]
} else if (sum === 21) {
message = "Wohoo!, you've got BlackJAck"
hasBlackJack = true
document.getElementById("q-heading").textContent = message
document.getElementById("sum-p").textContent = "Sum: " + sum
// document.getElementById("cards-p").textContent = "Cards: " + firstCard + " and " + secondCard
} else {
message = "You're out of the game"
isAlive = false
document.getElementById("q-heading").textContent = message
document.getElementById("sum-p").textContent = "Sum: " + sum
// document.getElementById("cards-p").textContent = "Cards: " + firstCard + " and " + secondCard
}
for (let i = 0; i < cards.length; i++) {
console.log(cards[i])
cardsEl.textContent += cards[i] + " "
}
}
function new_card() {
if(hasBlackJack === false && isAlive === true){
let newCard = getRandomCard()
sum += newCard
cards.push(newCard)
render_game()
} else {
console.log("You are out of the game.")
}
}