-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (38 loc) · 1.09 KB
/
Copy pathscript.js
File metadata and controls
44 lines (38 loc) · 1.09 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
let string = "";
let buttons = document.querySelectorAll('.button');
Array.from(buttons).forEach((button)=>{
button.addEventListener('click', (e)=>{
if(e.target.innerHTML == '='){
string = eval(string)
document.querySelector('input').value = string;
}
else if(e.target.innerHTML == 'C'){
string = ""
document.querySelector('input').value = string;
}
else{
console.log(e.target)
string = string + e.target.innerHTML;
document.querySelector('input').value = string;
}
})
})
// for clear screen
function calculateResult() {
try {
string = eval(string);
document.getElementById('display').value = string;
} catch (error) {
document.querySelector('input').value = 'Error';
}
}
// for clear number one by one
function clearOneCharacter() {
const inputField = document.querySelector('input');
const currentValue = inputField.value;
if (currentValue.length > 0) {
const newValue = currentValue.slice(0, -1);
inputField.value = newValue;
string = newValue;
}
}