-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
34 lines (27 loc) · 1.05 KB
/
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
let input = document.getElementById('inputBox'); // We have create on Id in Input
let buttons = document.querySelectorAll('button'); // It takes all buttons in the document
let string = "";
let arr = Array.from(buttons);
arr.forEach(button => {
button.addEventListener('click', (e) => {
if(e.target.innerHTML == '='){
// evaluate ek inbuilt funcation hai JavaScript me
// ese hoga aesa humare string me jo bhi kuch hoga use evalate karke wo hume de dega mathamatically
string = eval(string);
input.value = string; // input tag me value store karwa dege
// jabhi = par click hoga to jo bhi result hoga wo hume input value me dikhega
}
else if (e.target.innerHTML == 'AC') {
string = "";
input.value = string;
}
else if (e.target.innerHTML == 'DEL') {
string = string.substring(0, string.length - 1);
input.value = string;
}
else {
string += e.target.innerHTML;
input.value = string;
}
})
})