-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (64 loc) · 1.58 KB
/
Copy pathscript.js
File metadata and controls
78 lines (64 loc) · 1.58 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
/*code by vishal */
var rn=0;
var hiting;
//for random bubbles
function makeBubble()
{
var clutter="";
for(let i=0;i<=101;i++)
{
let a=Math.floor(Math.random()*10);
clutter+=`<div class="bubble">${a}</div>`
}
document.querySelector("#pbtm").innerHTML=clutter;
}
//for Hit
function hitBubble(){
hiting = setInterval(()=>{
rn=Math.floor(Math.random()*10);
document.querySelector("#hit").textContent=rn;
},2500)
}
//for timer
var timer = 60;
function setTimer()
{
setTimeout(()=>{
var timing = setInterval(()=>{
if(timer>0){
timer--;
document.querySelector("#timer").textContent=timer;
}
else{
clearInterval(timing);
clearInterval(hiting);
document.querySelector("#pbtm").innerHTML=`<h1>Game Over<br>Score:${score}</h1>`;
}
},1000)
},2000)
}
//for score
var score = 0;
function getscore(){
score += 10;
document.querySelector("#score").textContent=score;
}
//EventBubbling
//sare bubbles pe ek ek karke lagane ki jagah sbke common parent pe listener lga do.
document.querySelector("#pbtm")
.addEventListener('click',(detailsofselectedbubble)=>{
// alert("clicked")
// console.log(detailsofselectedbubble.target);
console.log(Number(detailsofselectedbubble.target.textContent));
var clickednum = Number(detailsofselectedbubble.target.textContent);
if(clickednum === rn)
{
getscore();
makeBubble();
}
})
makeBubble();
hitBubble();
setTimer();
// getscore();
/*code by vishal */