-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfull.js
89 lines (68 loc) · 1.68 KB
/
full.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
let cards = [];
let sum = 0;
let hastheblackjack = false;
let isAlive = false;
let message = '';
let words = document.getElementById('message-el');
let sumEl = document.getElementById('sum-el');
let cardsEL = document.getElementById('cards-el');
let player = {
nameis:'Player',
BetWorth:10
};
let cashdisplayhere = document.getElementById('cashdisplay');
let playerEL = document.getElementById('player-el');
playerEL.textContent = player.nameis + " $ " + ' - Each Game Worth $10';
function getr(){
let randomthenumber = Math.floor((Math.random())*13 +1 );
if ( randomthenumber > 10) {
return 10;
}
else if ( randomthenumber === 1) {
return 11;
} else {
return randomthenumber;
}
}
function startgame() {
isAlive = true;
let firstCard = getr();
let secondCard = getr();
cards = [firstCard, secondCard];
sum = firstCard + secondCard;
rendergame()
}
function rendergame() {
let cashplus = '';
let cashsubtract = '';
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 = 'wow Blackjack'
cashplus = 10;
hastheblackjack = true;
} else {
message = "You're out of the game!"
cashsubtract += -10;
isAlive = false;
} words.textContent = message;
cashdisplayhere.textContent = cashplus + cashsubtract;
};
function newcard(){
if (isAlive === true && hastheblackjack === false ) {
let card = getr();
sum += card;
cards.push(card);
rendergame();
}
}
// function toshowthecash(){
// if (condition) {
// } else {
// }
// }