-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
49 lines (48 loc) · 1.24 KB
/
Copy pathscript.js
File metadata and controls
49 lines (48 loc) · 1.24 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
alert("Welcome to the Game")
var name = prompt("Enter your name");
var bubbles = document.querySelector("#bubbles");
var time = 60;
var scr = 0;
var hits = 0;
function show() {
var clutter = "";
for (var i = 0; i < 40; i++) {
var random = Math.floor(Math.random() * 10);
clutter += `<div id="bubble">${random}</div>`;
}
bubbles.innerHTML = clutter;
}
function timer() {
setInterval(function () {
if (time >= 0) {
document.querySelector("#timer .box").textContent = time;
--time;
} else{
clearInterval();
bubbles.innerHTML = `<div id="scoreCard"><h1>Game Over!!</h1><div></div><p>Hello ${name}</p><p>Your Score : ${scr}<br>Total Hits : ${hits}</p></div>`;
}
}, 1000);
}
function hit(){
hits++;
document.querySelector("#hit .box").textContent = Math.floor(Math.random()*10);
}
function score(myScore){
document.querySelector("#score .box").textContent = myScore;
}
show();
timer();
hit();
score(scr);
bubbles.addEventListener("click", function(dets){
if(dets.target.textContent === document.querySelector("#hit .box").textContent){
score(scr += 10);
}
hit();
show();
})
document.querySelector("#retry").addEventListener("click", function(){
time = 60;
score(0);
show();
})