-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (58 loc) · 1.5 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
let first_card
let second_card
let array
let sum
let hasblackjack=false;
let isalive=false;
let message="";
let playername="vibhu";
let playerchips=145;
let player=document.getElementById("player");
player.textContent= playername + playerchips;
function random_number(){
let number=Math.floor(Math.random()*13)+1;
if(number>10){
return 10;
}else if(number === 1){
return 11;
}
else{
return number;
}}
function startGame(){
isalive=true;
first_card = random_number();
second_card =random_number();
array=[first_card,second_card];
sum=first_card+second_card;
renderGame();
}
function renderGame(){
document.getElementById("card-El").innerText='Cards: ';
for(let i=0;i<array.length;i++){
document.getElementById("card-El").textContent += array[i] + " ";
}
document.getElementById("sum-El").innerText= `Sum: ${sum}`;
if(sum <= 20){
document.getElementById("message-El").innerText="do you want to draw a card"
}
else if(sum === 21){
document.getElementById("message-El").innerText="wooh! you got black jack"
hasblackjack=true;
}
else{
document.getElementById("message-El").innerText="better luck next time";
isalive=false;
}
//cash out;
}
function newCard(){
if(isalive===true && hasblackjack===false){
let random;
random=random_number();
sum+=random;
array.push(random);
// let random_1=first_card+second_card+random;
renderGame();
}
}