-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
40 lines (38 loc) · 800 Bytes
/
main.js
File metadata and controls
40 lines (38 loc) · 800 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
32
33
34
35
36
37
38
39
40
let val;
val = document.getElementById('input');
function updatval(a){
val.value += a;
}
function dect(){
val.value = val.value.slice(0,-1);
}
function clearw(a){
if(a === '`'){
val.value = "";
}
}
function calc (){
val.value = eval(val.value);
}
//for hancling keyboard events
document.addEventListener('keydown' , function(event){
const key = event.key;
if(key === "Enter"){
event.preventDefault();
calc();
}
if(key === "Backspace"){
event.preventDefault();
dect();
}
if(key === "Escape"){
event.preventDefault();
clearw();
}
if(!isNaN(key) || key === '.' || key === '*' || key === '%' || key === '/' || key === '+' || key === '-'){
event.preventDefault();
updatval(key);
}
});
//for changing styles
document.querySelector()