-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (31 loc) · 1.01 KB
/
script.js
File metadata and controls
38 lines (31 loc) · 1.01 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
const output = document.querySelector(".output");
const result = document.querySelector(".result");
const keys = document.querySelectorAll("button");
keys.forEach(key=>{
key.addEventListener("click",calculate);
});
function calculate(){
let buttonText = this.innerText;
if(buttonText==="AC"){
output.innerText = "";
result.innerText = "0";
result.style.animation = "";
output.style.animation = "";
return;
}
if(buttonText === "DEL"){
output.textContent = output.textContent.substr(0,output.textContent.length-1);
return;
}
if(buttonText === "="){
result.innerText = eval(output.innerText);
result.style.animation = "big 0.5s ease-in-out";
output.style.animation = "small 0.5s ease-in-out";
result.style.animationFillMode = "forwards";
output.style.animationFillMode = "forwards";
}
else{
output.textContent += buttonText;
return;
}
}