-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathletscount.js
More file actions
49 lines (47 loc) · 1.05 KB
/
letscount.js
File metadata and controls
49 lines (47 loc) · 1.05 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
let answer;
let card;
let isAlive = false;
ya = document.getElementById("Cards");
yo = document.getElementById("Sum");
les = document.getElementById("result");
start_game = () => {
let firstCard = getRandomCard();
let secondCard = getRandomCard();
sum = firstCard + secondCard;
arr = [firstCard, secondCard];
isAlive =true;
render_game();
};
render_game = () => {
ya.textContent = "Cards :";
for (i = 0; i < arr.length; i++) {
ya.textContent += " " + arr[i];
}
yo.innerHTML = "Sum : " + sum;
if (sum < 21) {
les.innerHTML = "do u want to draw ";
} else if (sum === 21) {
les.innerHTML = "you won!!";
} else {
les.innerHTML = "you lost ";
}
};
function newcard() {
if(isAlive === false || sum>= 21)
return;
document.querySelector(".card_drawn").innerHTML = "Drawing a new card";
card = getRandomCard();
arr.push(card);
sum += card;
render_game();
}
function getRandomCard () {
let variable;
variable = Math.floor(Math.random() * 13);
if(variable === 1)
return 11;
else if(variable >= 10)
return 10;
else
return variable;
};