-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
40 lines (37 loc) · 1.04 KB
/
main.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
const switchbtn = document.getElementById('switch');
const display = document.getElementById('display');
const input = document.querySelectorAll('input');
let value = '';
// Darkmode swith
switchbtn.addEventListener('click', () => {
if (switchbtn.checked == true) {
document.body.setAttribute('data-theme', 'dark');
} else {
document.body.setAttribute('data-theme', '');
}
});
// Räkning
input.forEach((e) => {
e.addEventListener('click', (event) => {
if (event.target.value == '=') {
if (value.length != 0) {
let newval = eval(value);
value = newval;
display.value = value;
}
} else if (event.target.value == 'C') {
value = '';
display.value = value;
} else if (event.target.value == 'switch') {
} else {
value += event.target.value;
display.value = value;
}
if (!event.target.classList.contains('switch')) {
event.target.classList.add('active');
setTimeout(() => {
event.target.classList.remove('active');
}, 400);
}
});
});