-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (39 loc) · 1.02 KB
/
index.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
33
34
35
36
37
38
39
40
document.addEventListener("keydown",keyBoardButton)
function keyBoardButton(event){
var b=event.key;
compute(event.key);
buttonAnimation(event.key);
}
$("button").click(function(){
if ($(".display").val()==="Infinity" ){
var b="";
$(".display").val(b);
}
var b=this.innerHTML;
compute(b)
})
function compute(b){
if (b ==="="){
var total=eval($(".display").val());
$(".display").val(total);
}
else if(b==="C"){
var cl="";
$(".display").val(cl);
}
else if(b==="x" || b==="Backspace"){
var num="";
num=$(".display").val();
var len=num.length-1;
$(".display").val(num.slice(0,len));
}
else{
$(".display").val($(".display").val()+b);
}
}
function buttonAnimation(currentkey){
activebutton=document.querySelector(".div"+currentkey);
activebutton.classList.add("pressed");
setTimeout(function(){
activebutton.classList.remove("pressed");},100);
}