-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
143 lines (111 loc) · 3.18 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//console.log(4 === 3) // false
//console.log(5 > 2) // true
//console.log(12 > 12) // false
//console.log(3 < 0) // false
//console.log(3 >= 3) // true
//console.log(11 <= 11) // true
//console.log(3 <= 2) // false
let cards = []//Array oredered list of items
let messageEl = document.getElementById("message-el")
let cardEl = document.getElementById("card-el")
let sumEl = document.getElementById("sum-el")
let sum = 0
let hasBlackJack = false
let isAlive = false
let message = ""
//object structure
let playerEl = document.getElementById("player-el")
let player = {
name: "Erik",
chips: 145
}
playerEl.textContent = player.name + ": $" + player.chips
//end object structure
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() {
sumEl.textContent = "Sum: " + sum
cardEl.textContent = "Cards: "
for (let i = 0; i < cards.length; i++) {
cardEl.textContent += cards[i] + " "
}
if (sum <= 20) {
message = "Do you want to draw a new card?"
} else if(sum === 21){
message = "You have blackjack"
hasBlackJack = true
} else {
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()
}
}
//Cash out
//console.log(hasBlackJack)
//console.log(isAlive)
//let age = 100
//if (age < 100) {
// console.log("Not eligible")
//} else if (age === 100) {
// console.log("Here is your birthday card from the King!")
//} else {
// console.log("Not eligible, you have already gotten one")
//}
// Count to ten!
// We need to specify...
// Where should we START counting?
// Where is the FINISH line?
// What's the STEP SIZE we should use?
// START FINISH STEP SIZE
//for ( let count = 1; count < 11; count += 1 ) {
// console.log(count)
//}
//let messages = [
// "Hey, how's it going?",
// "I'm great, thank you! How about you?",
// "All good. Been working on my portfolio lately.",
// "Same here!",
// "Great to hear"
//]
// DRY - Don't repeat yourself
// console.log(messages[0])
// console.log(messages[1])
// console.log(messages[2])
// console.log(messages[3])
//for (let i = 0; i < 5; i += 1) {
// console.log(messages[i])
//}
//let cardigan = [7, 3, 9]
//for (let i = 0; i < cardigan.length; i++) {
// console.log(cardigan[i])
//}
//let sentence = ["Hello ", "my ", "name ", "is ", "Per"]
//let meetingEl = document.getElementById("meeting-el")
// Render the sentence in the greetingEl paragraph using a for loop and .textContent
//for (let i = 0; i < sentence.length; i++) {
// meetingEl.textContent += sentence[i]
//}