-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (34 loc) · 1.02 KB
/
script.js
File metadata and controls
46 lines (34 loc) · 1.02 KB
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
41
42
43
44
45
46
// input
// try{
// eval(input)
// }
// catch{
// error
// }
let display=document.getElementById('display')
let buttons=Array.from(document.getElementsByClassName('button'));
buttons.map(button =>{
button.addEventListener('click' ,(event)=>{
// console.log(event.target.innerText)
switch(event.target.innerText) {
case 'C' :
display.innerText='';
break;
case '←' :
if(display.innerText){
display.innerText=display.innerText.slice(0,-1);
}
break;
case '=' :
try {
display.innerText=eval(display.innerText);
}
catch {
display.innerText='error';
}
break;
default :
display.innerText +=event.target.innerText;
}
})
})