-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (36 loc) · 1.47 KB
/
script.js
File metadata and controls
40 lines (36 loc) · 1.47 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
const display = document.querySelector(".value")
const operators = document.querySelector(".operators");
const toggleMode = document.querySelector(".mode")
const form = document.querySelector(".calculator form");
// display.value = '';
operators.addEventListener("click", e => {
if (e.target.classList.contains("btn")) {
display.value += e.target.value;
}
else if (e.target.classList.contains("backspace")) {
display.value = display.value.slice(0, -1);
}
else if (e.target.classList.contains("clear")) {
display.value = "";
}
else if (e.target.classList.contains("equal")) {
display.value = eval(display.value);
}
})
form.addEventListener("submit", e => {
e.preventDefault();
})
toggleMode.addEventListener("click", e => {
if (e.target.innerHTML == "dark_mode") {
e.target.innerHTML = "light_mode"
document.querySelector(".calculator").style.backgroundColor = "#243540";
document.querySelectorAll("[type='button']:not(.equal):not(.number)").forEach(e => e.style.color = '#30a0e0');
display.style.color = "#fff";
}
else if (e.target.innerHTML == "light_mode") {
e.target.innerHTML = "dark_mode"
document.querySelector(".calculator").style.backgroundColor = "#ebeaea";
document.querySelectorAll("[type='button']:not(.equal):not(.number)").forEach(e => e.style.color = '#888');
display.style.color = "#243443";
}
})