-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (24 loc) · 754 Bytes
/
Copy pathscript.js
File metadata and controls
31 lines (24 loc) · 754 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
28
29
30
31
const input = document.querySelector('input');
const digitBtns = document.querySelectorAll('.btns')
const clr = document.querySelector('.clear')
const eql = document.querySelector('.equal')
const back = document.querySelector('.bk')
const ans = document.querySelector('span')
function calAns(){
ans.innerText = "= "+eval(input.value)
input.value = "";
}
input.onkeyup = e => (e.key === "Enter")? calAns():undefined
for(let digitBtn of digitBtns){
digitBtn.onclick = () => {
input.value += digitBtn.getAttribute('data-value');
}
}
clr.onclick = () => {
input.value = ""
ans.innerText = "0"
};
eql.onclick = () => calAns()
back.onclick = () => {
if(input.value !== "") input.value = input.value.substr(0, input.value.length - 1)
}