-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
85 lines (82 loc) · 2.28 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// var timer = +prompt("Enter You timer");
var timer = 0;
var score = 0;
var rnHitValue = 0;
var inputTime = 0;
var bgFlag = 0;
var hitBg = document.querySelector('#hitValue');
function bubbleMaker() {
var clutter = '';
for (let i = 0; i <= 179; i++) {
var num = Math.floor(Math.random() * 10);
clutter += ` <div class="bubble">
<h1>${num}</h1>
</div>`;
}
document.querySelector('.panel-bottom').innerHTML = clutter;
}
function getNewHit() {
rnHitValue = Math.floor(Math.random() * 10);
document.querySelector('#hitValue').textContent = rnHitValue;
}
function runTimer() {
var timerBreak = setInterval(function () {
if (timer > 0) {
timer--;
document.querySelector('#timerValue').textContent = timer;
} else {
clearInterval(timerBreak);
document.querySelector('.panel-bottom').innerHTML = `
<div class="gameOverBox">
<h2>Game Over ⛳️</h2>
<h2 id="inputTime">Time🕰️-${inputTime} </h2>
<h1>Your Score :-<span id="totalScore"> ${score}</span></h1>
<button onclick="refreshFn()">Start New Game</button>
</div>`;
document.querySelector('#hitValue').textContent = 0;
}
}, 1000);
}
function increaseScore() {
score += 10;
document.querySelector('#scoreValue').textContent = score;
}
function decreaseScore() {
score -= 10;
document.querySelector('#scoreValue').textContent = score;
}
document.querySelector('.panel-bottom').addEventListener('click', details => {
// console.log(Number(details.target.textContent));
var clickedNum = Number(details.target.textContent);
if (clickedNum === rnHitValue) {
increaseScore();
bubbleMaker();
getNewHit();
}
if (bgFlag === 0) {
hitBg.style.backgroundColor = '#738a8a';
bgFlag = 1;
} else {
hitBg.style.backgroundColor = '#a0c8c8';
bgFlag = 0;
}
});
document
.querySelector('.timer-select-container')
.addEventListener('click', details => {
// console.log(Number(details.target.textContent));
var clickedNum = Number(details.target.textContent);
timer = clickedNum;
inputTime = clickedNum;
document.querySelector('.panel-bottom').innerHTML = ``;
bubbleMaker();
runTimer();
getNewHit();
});
function refreshFn() {
location.reload(true);
}
// bubbleMaker();
// getNewHit();
// runTimer();
// console.log(timer)