-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
50 lines (41 loc) · 1.13 KB
/
script.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
var timer=30;
var score=0;
var hit=0;
function addScore(){
score += 10;
document.querySelector("#scorevalue").textContent=score;
}
function makebubble(){
var set_bubble="";
for(var i=1;i<=136;i++){
set_bubble +=`<div class="bubble">${Math.floor(Math.random()*10)}</div>`;
}
document.querySelector("#panelbottom").innerHTML=set_bubble;
}
function startTimer(){
var time_int=setInterval(function(){
if(timer>0){
timer--;
document.querySelector("#timevalue").textContent=timer;
}
else{
clearInterval(time_int);
document.querySelector("#panelbottom").innerHTML=`<h1 style="font-size: 100px;"><b>GAME OVER</b></h1><h1>Your Score:${score}</h1>`;
}
},1000);
}
function getHit(){
hit=Math.floor(Math.random()*10);
document.querySelector("#hitvalue").textContent=hit;
}
document.querySelector("#panelbottom").addEventListener("click",function(details){
var bubble_digit=Number(details.target.textContent);
if(bubble_digit===hit){
addScore();
makebubble();
getHit();
}
});
getHit();
startTimer();
makebubble();