-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (26 loc) · 834 Bytes
/
script.js
File metadata and controls
30 lines (26 loc) · 834 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
let string=""
let buttons=document.querySelectorAll(".button")
Array.from(buttons).forEach((button)=>{
button.addEventListener('click',(event)=>{
try{
if(event.target.innerHTML == '='){
string=eval(string)
document.querySelector('input').value=string
}
else if(event.target.innerHTML=='C'){
string=""
document.querySelector('input').value=string
}
else{
if (event.target.innerHTML == 'X') {
string += '*';
} else {
string += event.target.innerHTML;
}
document.querySelector('input').value = string;
}
}catch{
document.querySelector("input").value="Syntax Error"
}
})
})