-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (24 loc) · 941 Bytes
/
script.js
File metadata and controls
26 lines (24 loc) · 941 Bytes
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
document.addEventListener('DOMContentLoaded', function () {
const display = document.getElementById('display');
const buttons = document.querySelectorAll('.btn');
buttons.forEach(button => {
button.addEventListener('click', () => {
const value = button.getAttribute('data-value');
if (value === 'C') {
display.textContent = '0';
} else if (value === '=') {
try {
display.textContent = eval(display.textContent.replace('%', '/100'));
} catch {
display.textContent = 'Error';
}
} else {
if (display.textContent === '0' || display.textContent === 'Error') {
display.textContent = value;
} else {
display.textContent += value;
}
}
});
});
});