-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
62 lines (50 loc) · 1.56 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
let displayValue = 0;
function updateDisplay() {
document.getElementById("display").textContent = displayValue;
}
function removenum() {
numvalue = document.getElementById("display").textContent;
numvalue = parseInt(numvalue / 10);
displayValue = numvalue;
updateDisplay();
}
function appendToDisplay(value) {
if (displayValue === 0) {
displayValue = "";
}
if (value === '=' && displayValue !== "") {
try {
displayValue = eval(displayValue).toString();
} catch (error) {
displayValue = "Error";
}
} else {
displayValue += value;
}
updateDisplay();
}
function clearDisplay() {
displayValue = "0";
updateDisplay();
}
function calculateResult() {
appendToDisplay('=');
}
// Initial display setup
updateDisplay();
function changemode() {
const element = document.getElementById("calc");
const label = document.querySelector('.mode .form-switch .form-check-input');
if (element.classList.contains("light-calculator")) {
element.classList.remove("light-calculator");
element.classList.add("dark-calculator");
document.getElementById("mode_name").textContent = "Dark Mode";
label.style.backgroundColor = "black";
}
else {
element.classList.remove("dark-calculator");
element.classList.add("light-calculator");
document.getElementById("mode_name").textContent = "Light Mode";
label.style.backgroundColor = "white";
}
}