-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
106 lines (85 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Creating Toggle
let light = document.querySelector("#light");
let dark = document.querySelector("#dark");
let background = document.querySelector("#background");
let toggle = {
light: {
bg: "white",
fg: "black",
},
dark: {
fg: "white",
bg: "black",
},
};
light.addEventListener("click", function () {
background.style.backgroundColor = toggle.light.bg;
background.style.color = toggle.light.fg;
});
dark.addEventListener("click", function () {
background.style.backgroundColor = toggle.dark.bg;
background.style.color = toggle.dark.fg;
});
//Creating Bubbles
let canvas = document.querySelector("#canvas");
// Creating Array
let colors = ["#ff7979", "#badc58", "#22a6b3", "#2ecc71", "#ffbe76", "#e056fd"];
function makeBubbles() {
for (i = 0; i < 54; i++) {
let randomNumber = Math.floor(Math.random() * colors.length);
canvas.innerHTML += `<div class="bubble" style="background-color: ${colors[randomNumber]}";></div>`;
}
}
makeBubbles();
//Creating Function for Guessing Color
let guess = document.querySelector("#guess");
function guessColor() {
let randomColorIndex = Math.floor(Math.random() * colors.length);
guess.style.backgroundColor = colors[randomColorIndex];
}
guessColor();
//Creating Timer
let start = 60;
let time = document.querySelector("#time");
function timer() {
if (start > 0) {
start--;
time.innerHTML = start;
} else {
canvas.style.display = "none";
final.style.display = "block";
point.innerHTML = points;
canvas.style.backgroundColor = "#fefefe";
}
}
setInterval(timer, 1000);
// Scoring
let points = 0;
canvas.addEventListener("click", function (e) {
// console.log(e);
let num = e.target.style.backgroundColor;
console.log(num);
if (num == guess.style.backgroundColor) {
points = points + 1;
score.innerHTML = points;
canvas.innerHTML = "";
makeBubbles();
guessColor();
}
});
let btn = document.querySelector(".btn");
btn.addEventListener("click", function () {
location.reload();
});
// Add the else part in Session 3
// function timer() {
// if (start > 0) {
// start--;
// time.innerHTML = start;
// } else {
// canvas.style.display = 'none';
// final.style.display ='block';
// point.innerHTML= points;
// canvas.style.backgroundColor = "#fefefe";
// }
// }