-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
99 lines (72 loc) 路 1.95 KB
/
Copy pathscript.js
File metadata and controls
99 lines (72 loc) 路 1.95 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
97
98
99
let player = {
name: "per",
chips: 145
}
let cards = [];
let sum = 0;
let hasBlackJack = false;
let isAlive = false;
let message = "";
let messageEl = document.getElementById("message-el");
let sumEl = document.querySelector("#sum-el");
let cardsEl = document.querySelector("#cards-el");
let playerEl = document.getElementById("player-el");
playerEl.textContent = player.name + ": $" + player.chips;
console.log(cards);
function startGame(){
hasBlackJack = false;
isAlive = true;
let firstCard = getRandomCard();
let secondCard = getRandomCard();
cards = [firstCard, secondCard];
sum = firstCard + secondCard;
renderGame();
}
function getRandomCard(){
let randomNumber = Math.floor(Math.random() * 13) + 1;
return randomNumber;
}
function renderGame() {
// sumEl.textContent = `Sum: ${sum}` || "Sum: " + sum;
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){
message = "You have got Blackjack!";
hasBlackJack = true;
}
else {
message = "You are 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();
}
}
// let age = 22;
// if (age >= 21){
// console.log("welcome")
// }
// else {
// console.log("You can not enter the club!")
// }
// let mi = {
// name: "Ahmed",
// age: 25 +" years old",
// country: "egypt"
// }
// function logData () {
// console.log(mi.name + " is " + mi.age + " and live in " + mi.country);
// }
// logData();