-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex1.js
86 lines (74 loc) · 1.45 KB
/
index1.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
function rand()
{
return (1+Math.floor(Math.random()*13));
}
let firstc = 0;
let secc = 0;
let cards=[];
let isblackj=false;
let isalive=true;
let mes="";
let sum=0;
let varb= false;
// let mesEl = document.getElementById("card");
// let mesEl = document.querySelector(".dd");
let mesEl=document.querySelector("#card");
console.log(mesEl);
let el = document.getElementById("sum");
let cd=document.getElementById("cc");
function startg()
{
firstc=rand();
secc=rand();
cards=[firstc,secc];
sum=firstc+secc;
renderg();
}
function renderg()
{
if(!varb)
firstc = rand();
secc = rand();
if(sum<=20)
{
mes="Do you want to draw the next card? ";
}else if(sum===21) /*== gives true age=="100" but === is strict , it knows we are comparing an int with string */
{
mes="Congrats! you have made it";
isblackj=true;
}else{
mes="Sorry, you have lost the game";
isalive=false;
}
mesEl.textContent=mes;
el.textContent="Sum: "+sum;
cd.textContent="Cards: ";
let i=0;
for(i=0;i<cards.length;i++)
{
cd.textContent+=cards[i]+" ";
}
}
let v=rand();
function newc()
{
varb = true;
if(sum<21&&sum!=0)
{
cards.push(v);
sum=sum+v;
console.log(sum);
{renderg();}
}
}
//challenge
let ob1={
name:"Ragini",
chips:500,
// sayhello:function(){
// console.log("Hello");
// }
}
let para=document.getElementById("myid");
para.textContent=ob1.name+" :$"+ob1.chips;
// ob1.sayhello();