-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
28 lines (25 loc) · 843 Bytes
/
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
document.addEventListener('DOMContentLoaded',function(){
const screen = document.querySelector('.screen');
const buttons = document.querySelectorAll('.buttons div');
let currentInput='';
let result='';
buttons.forEach(button=>{
button.addEventListener("click",()=>{
const value = button.textContent;
if (value === "CE") {
currentInput = "";
result = "";
} else if (value === "=") {
try {
result = eval(currentInput);
} catch {
result = "Error";
}
currentInput = result;
} else {
currentInput += value;
}
screen.textContent = currentInput || result || "0";
})
})
})