forked from sidrakhalid4488/codsoft_task2-Calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
41 lines (27 loc) · 886 Bytes
/
script.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
35
36
37
38
39
40
41
let inputBox = document.getElementById('inputBox')
let buttons = document.querySelectorAll('button')
let string= ''
buttons.forEach(element=>{
element.addEventListener('click', (b) =>{
if(b.target.innerText=='='){
string=String(eval(string))
inputBox.value=string;
}
else if(b.target.innerText== 'AC'){
string = ''
inputBox.value = string;
}
else if(b.target.innerText== 'DEL'){
string = string.substring(0,string.length-1)
inputBox.value = string;
}
else if(b.target.id =='plusMinus'){
string = String(-eval(string))
inputBox.value = string;
}
else{
string += b.target.innerText
inputBox.value = string;
}
})
})