-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
69 lines (58 loc) · 1.68 KB
/
script.js
File metadata and controls
69 lines (58 loc) · 1.68 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
document.addEventListener("DOMContentLoaded", function () {
let timer=60;
let hitval;
let score=0;
function make_Bubble(){
let pbtm = document.querySelector("#panelbottom");
let container = "";
console.log("JS connected");
for (let i = 0; i < 102; i++) {
let rn = Math.floor(Math.random() * 10 + 1);
container += `<div class="bubble">${rn}</div>`;
}
pbtm.innerHTML = container;
}
function set_Timer(){
let interval=setInterval(function(){
if(timer>0){
timer--;
document.querySelector('#timer').textContent=timer;
}
else{
clearInterval(interval);
document.querySelector("#panelbottom").innerHTML=`<h1 class="over">GAME OVER</br>SCORE= ${score}</h1>`
}
},1000);
}
function new_Hit(){
hitval=Math.floor(Math.random()*10+1);
document.querySelector("#hit").textContent=hitval;
}
function inc_Score(){
score+=10;
document.querySelector('#score').textContent=score;
}
function dec_Score(){
score-=5;
document.querySelector('#score').textContent=score;
}
function game(){
document.querySelector('#panelbottom').addEventListener('click',(e)=>{
let val=Number(e.target.textContent)
if(val===hitval){
inc_Score();
make_Bubble();
new_Hit();
}
else{
dec_Score();
make_Bubble();
new_Hit();
}
})
}
make_Bubble();
set_Timer();
new_Hit();
game();
});