-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathindex.js
61 lines (53 loc) · 1.57 KB
/
index.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
var timerValue = 30;
var scoreValue = 0;
var hitsValue = 0;
const createBubble = () => {
var contentbox = '';
for (let i = 1; i < 208; i++) {
contentbox += `<div class="bubble"'>${Math.floor(Math.random() * 10)}</div>`;
}
document.querySelector('.content').innerHTML = contentbox;
}
const setTimeing = () => {
var timerNode = document.querySelector('.timer');
const timeInterval = setInterval(() => {
if (timerValue > 0) {
timerValue--;
timerNode.textContent = timerValue;
}
else {
clearInterval(timeInterval);
document.querySelector('.content').innerHTML = '<h1 class="gameOver">Game Over <br><button onclick="restartGame()">Restart</button></h1>';
}
}, 1000);
}
const hitsgenerate = () => {
hitsValue = Math.floor(Math.random() * 10);
console.log(hitsValue);
document.querySelector('.hitsvalue').textContent = hitsValue;
}
const score = () => {
scoreValue += 10;
document.querySelector('.scoreValue').textContent = scoreValue;
}
document.querySelector('.content').addEventListener('click', (e) => {
if (Number(e.target.textContent) === hitsValue) {
score();
createBubble();
hitsgenerate();
}
// console.log(Number(e.target.textContent));
})
const restartGame = () => {
scoreValue = 0;
document.querySelector('.scoreValue').textContent = scoreValue;
timerValue = 30;
createBubble();
setTimeing();
hitsgenerate();
}
const Startingfun = () => {
createBubble();
setTimeing();
hitsgenerate();
}