-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
62 lines (55 loc) · 1.99 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
51
52
53
54
55
56
57
58
59
60
61
62
var timer = 60;
var score = 0;
var hitrn = 0;
var fscore;
// jispe click karoge wo element par event raise hoga , aur event listner na milne par event element ke parent par listner dhundega wha bhi na milne par event parent ke parent ke parent par listner dhundega
function increaseScore() {
fscore = score += 10;
document.querySelector("#scoreval").textContent = score;
}
function makebubble() {
var clutter = "";
for (var i = 0; i <= 101; i++) {
var rn = Math.floor(Math.random() * 10);
// floor remove decimar and math.random generate any number btw 0 to 1 so we multiply it by 10
clutter += `<div class="bubble">${rn}</div>`;
// yha ise store karana jaruri hai isliye ise var bnake clutter name se save kar diya
// agar ham = lagate he to wha pichla div remove hota rhega and nya banta rhega to isliye hamne use kiya += ka jo pichla save kara rhega aur agla bnata rhega
}
document.querySelector("#pbtm").innerHTML = clutter;
}
function runtimer() {
var timerit = setInterval( function () {
if (timer > 0) {
timer--;
document.querySelector("#timervalue").textContent = timer;
}
else{
document.querySelector(
"#pbtm"
).innerHTML = `<h1> GAME OVER!</h1> <br> <h2>Score ${fscore} </h2> `;
clearInterval(timerint);
}
} , 1000);
}
function getnewhit() {
hitrn = Math.floor(Math.random() * 10);
document.querySelector("#hitval").textContent = hitrn;
}
document.querySelector("#pbtm").addEventListener("click", function (details) {
var clickednum = Number(details.target.textContent);
if (clickednum == hitrn) {
var audio = new Audio("correct answer.mp3");
audio.play();
increaseScore();
makebubble();
getnewhit();
}
else {
var audio = new Audio("wrong answer.mp3");
audio.play();
}
});
getnewhit();
runtimer();
makebubble();