-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
89 lines (74 loc) · 2.3 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
86
87
88
89
var timer = 30;
var newHit;
var score = 0;
function makeBubble() {
var clutter = "";
var mediaQuery = window.matchMedia('(max-width: 600px)')
if (mediaQuery.matches) {
console.log("300")
for (var i = 1; i < 41; i++) {
var rn = Math.floor(Math.random() * 10)
clutter += `<div class="bubble">${rn}</div>`
}
document.querySelector(".pbtm").innerHTML = clutter
}
else {
console.log("700")
for (var i = 1; i < 161; i++) {
var rn = Math.floor(Math.random() * 10)
clutter += `<div class="bubble">${rn}</div>`
}
document.querySelector(".pbtm").innerHTML = clutter
}
// document.querySelector(".pbtm").innerHTML = clutter
//Math.random() gives random number between 0 & 1 viz in decimal
//Multiplying 10 with the Math.random() function gives a whole number followed by decimmal eg. 1.263, 5.123, 9.2134
//Using floor function to Math.random()*10, it will give a random single digit number
}
function runTimer() {
var timerint = setInterval(function () {
if (timer > 0) {
timer--;
document.querySelector(".timerval").textContent = timer;
}
else {
clearInterval(timerint);
document.querySelector(".pbtm").innerHTML = `<h1 class="over">Game Over</h1>`;
}
}, 1000);
}
function getNewHit() {
newHit = Math.floor(Math.random() * 10);
document.querySelector(".hitval").textContent = newHit;
}
function increaseScore() {
score += 10;
document.querySelector(".scoreval").textContent = score;
}
document.querySelector(".pbtm").addEventListener("click", function (dets) {
var clickedNumber = (Number(dets.target.textContent));
if (clickedNumber === newHit) {
increaseScore();
getNewHit();
makeBubble();
}
})
var box1 = document.querySelector(".box1");
var icon = document.querySelector(".icon");
var bg = document.querySelector(".bg-image");
box1.addEventListener("click", function() {
console.log("working")
document.body.classList.toggle("dark-theme");
if(document.body.classList.contains("dark-theme"))
{
icon.src="half-moon.png";
bg.style.backgroundImage = "url('pink.jpg')";
}
else{
icon.src="cloud.png";
bg.style.backgroundImage = "url('night.png')";
}
})
getNewHit();
runTimer();
makeBubble();