-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
49 lines (41 loc) · 1.38 KB
/
script.js
File metadata and controls
49 lines (41 loc) · 1.38 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
// script for counter logic
/* Selecting the element with the id of display. */
let display = document.querySelector("#display");
/* Declaring a variable called value and assigning it a value of 0. */
let value = 0;
/* A function that is being called when the button is clicked. */
document.querySelector("#decrement").addEventListener("click", () => {
value--;
display.innerHTML = value;
});
document.querySelector("#reset").addEventListener("click", () => {
value = 0;
display.innerHTML = value;
});
document.querySelector("#increment").addEventListener("click", () => {
value++;
display.innerHTML = value;
});
/* Listening for a keypress event on the increment button. */
document.querySelector("#increment").addEventListener("keypress", (event) => {
if (event.keyCode === 13) {
value++;
display.innerHTML = value;
}
});
// script for the toggling
let toggle = document.querySelector("#toggle");
let body = document.querySelector("body");
/* Toggling the background color and the text color. */
toggle.addEventListener("click", function () {
this.classList.toggle("bi-moon");
if (this.classList.toggle("bi-brightness-high-fill")) {
body.style.background = "rgb(255, 132, 100)";
body.style.color = "black";
body.style.transition = "2s";
} else {
body.style.background = "black";
body.style.color = "white";
body.style.transition = "2s";
}
});