-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
47 lines (43 loc) · 1.11 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
let timer = 30;
let score = 0;
let hitrn = 0;
function makeBubble() {
var clutter = "";
for (var i = 1; i <= 114; i++) {
let rand = Math.floor(Math.random() * 10);
clutter += `<div class = "bubble">${rand}</div>`;
}
document.querySelector(".pbtm").innerHTML = clutter;
}
function runTimer() {
let timerun = setInterval(function () {
if (timer > 0) timer--;
else {
clearInterval(timerun);
document.querySelector(".pbtm").innerHTML = `<h1>Game Over <br><br>
Your Score is : ${score} <br><br>
Thank's for playing</h1>`;
}
document.querySelector(".timer").textContent = timer;
}, 1000);
}
function hitscount() {
hitrn = Math.floor(Math.random() * 10);
document.querySelector(".hits").textContent = hitrn;
}
function increaseScore() {
score += 10;
document.querySelector(".score").textContent = score;
}
document.querySelector(".pbtm").addEventListener("click", function (e) {
let bubclick = Number(e.target.textContent);
if (bubclick === hitrn) {
increaseScore();
makeBubble();
hitscount();
} else {
}
});
makeBubble();
runTimer();
hitscount();