-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (27 loc) · 942 Bytes
/
script.js
File metadata and controls
30 lines (27 loc) · 942 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
27
28
29
30
document.addEventListener('DOMContentLoaded', function() {
const inputField = document.querySelector('.screen input');
const buttons = document.querySelectorAll('.buttons button');
buttons.forEach(button => {
button.addEventListener('click', function() {
const value = this.innerText;
if (value === '=') {
try {
inputField.value = eval(inputField.value);
} catch (e) {
inputField.value = 'Error';
}
} else {
inputField.value += value;
}
});
});
inputField.addEventListener('keypress', function(event) {
if (event.key === 'Enter') {
try {
inputField.value = eval(inputField.value);
} catch (e) {
inputField.value = 'Error';
}
}
});
});