-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.js
34 lines (31 loc) · 885 Bytes
/
calculator.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
29
30
31
32
33
34
let btn=document.querySelectorAll('.but');
let display=document.querySelector('.div1');
let str="";
for(b of btn) {
b.addEventListener('click',(e)=>{
if(e.target.innerText=="AC") {
str="";
display.innerText=str;
console.log('chla')
}
else if(e.target.innerText=="DE") {
console.log(typeof(str))
str=str.substring(0, str.length-1);
console.log(str)
display.innerText=str;
}
else if(e.target.innerText=="=") {
console.log('equal')
str=(eval(display.innerText))
console.log(str)
display.innerText=str
str=str.toString();
}
else {
console.log(e.target.innerText)
str+=e.target.innerText;
display.innerText=str;
console.log(str)
}
})
}