-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
27 lines (27 loc) · 804 Bytes
/
script.js
File metadata and controls
27 lines (27 loc) · 804 Bytes
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
console.log("welcome to parambrata's calculator");
let btn = document.querySelectorAll("button")
let input = document.querySelector("input")
btn.forEach((e) => {
e.addEventListener("click", function ()
{
let currentValue = input.value;
let newValue = e.innerHTML;
if (e.innerHTML !== "=") {
input.value = currentValue + '' + newValue;
}
if (e.innerHTML == "="){
let val = input.value
val.trim()
let result = eval(val)
input.value = result
}
if (e.innerHTML == "C"){
let val = input.value
let nlsc = val.substring(0,val.length - 2)
input.value = nlsc
}
if (e.innerHTML == "CE"){
input.value = ""
}
})
});