-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
71 lines (62 loc) · 2.23 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
const themeToogle = document.getElementById("themeToogle");
const setTheme = localStorage.getItem("theme");
if (setTheme == "dark") {
// light to dark
document.documentElement.style.setProperty("--bg-color", "#040D12");
document.documentElement.style.setProperty("--text-color", "#93B1A6");
document.documentElement.style.setProperty("--keypad-bg-color", "#040D12");
document.documentElement.style.setProperty("--keypad-bg-color2", "#183D3D");
themeToogle.checked = true;
} else {
document.documentElement.style.setProperty("--bg-color", "#F1EAFF");
document.documentElement.style.setProperty("--text-color", "#D67BFF");
document.documentElement.style.setProperty("--keypad-bg-color", "#F1EAFF");
document.documentElement.style.setProperty("--keypad-bg-color2", "#D0A2F7");
}
themeToogle.addEventListener("change", function () {
if (this.checked) {
// light to dark
document.documentElement.style.setProperty("--bg-color", "#040D12");
document.documentElement.style.setProperty("--text-color", "#93B1A6");
document.documentElement.style.setProperty("--keypad-bg-color", "#040D12");
document.documentElement.style.setProperty("--keypad-bg-color2", "#183D3D");
localStorage.setItem("theme", "dark");
} else {
document.documentElement.style.setProperty("--bg-color", "#F1EAFF");
document.documentElement.style.setProperty("--text-color", "#D67BFF");
document.documentElement.style.setProperty("--keypad-bg-color", "#F1EAFF");
document.documentElement.style.setProperty("--keypad-bg-color2", "#D0A2F7");
}
});
let result = document.getElementById("result");
function appendToResult(value) {
result.value += value;
playButtonSound();
}
function backspace() {
if(result.value == 'Error'){
result.value = '';
}
result.value = result.value.slice(0, -1);
playButtonSound();
}
function clearResult() {
result.value = "";
playButtonSound();
}
function calculate() {
try {
if (result.value == "") {
result.value = "0";
}
result.value = eval(result.value);
} catch (error) {
result.value = "Error";
}
playButtonSound();
}
function playButtonSound() {
const buttonSound = document.getElementById('buttonSound');
buttonSound.currentTime = 0;
buttonSound.play();
}