-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
64 lines (53 loc) · 1.91 KB
/
script.js
File metadata and controls
64 lines (53 loc) · 1.91 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
var clutter = '';
function creatingBubbles() {
for (var i = 1; i <= 60; i++) {
clutter += `<div class="bubble">${Math.floor(Math.random()*10)}</div>`;
}
document.querySelector('.bottom').innerHTML = clutter;
}
var countDown = 60;
function creatingBubbles() {
var bubbleContainer = document.querySelector('.bottom');
bubbleContainer.innerHTML = ''; // Clear existing bubbles
for (var i = 1; i <= 60; i++) {
var bubbleValue = Math.floor(Math.random() * 10);
var bubble = document.createElement('div');
bubble.classList.add('bubble');
bubble.textContent = bubbleValue;
bubbleContainer.appendChild(bubble);
}
}
function settingTimer() {
var timerInterval = setInterval(function () {
countDown--;
if (countDown >= 0) {
document.querySelector('.timer').textContent = countDown;
} else {
clearInterval(timerInterval);
document.querySelector('.bottom').innerHTML = `<h1 id="over">Game over</h1>`;
}
}, 1000);
}
function hitVal() {
return Math.floor(Math.random() * 10);
}
function checkClick() {
var hit = hitVal();
document.querySelector('.hit').textContent = hit;
document.querySelector('.bottom').addEventListener('click', function (dets) {
if (dets.target.classList.contains('bubble') && dets.target.textContent == hit) {
scoreNum += 10;
document.querySelector('.score').textContent = scoreNum;
hit = hitVal();
document.querySelector('.hit').textContent = hit;
var bubbles = document.querySelectorAll('.bubble');
bubbles.forEach(function (bubble) {
bubble.textContent = Math.floor(Math.random() * 10);
});
}
});
}
var scoreNum = 0;
checkClick();
creatingBubbles();
settingTimer();