-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
59 lines (55 loc) · 1.3 KB
/
script.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const buttons=document.querySelectorAll("button");
const display=document.querySelector(".display");
let current_value="";
const max_len=15;
buttons.forEach(button=>
{
button.addEventListener("click",function()
{
const icon = this.querySelector("i");
let val="";
if (icon) {
if (icon.classList.contains("fa-xmark"))
{
val = "*";
} else if (icon.classList.contains("fa-divide"))
{
val = "/";
}
else if (icon.classList.contains("fa-delete-left")) {
current_value = current_value.slice(0, -1);
display.textContent = current_value || "0";
return;
}
}
else
{
val=this.textContent.trim();
}
if(val==="C")
{
current_value="";
}
else if(val==="=")
{
try
{
current_value=eval(current_value);
}
catch(error)
{
current_value="Error";
}
}
else
{
current_value+=val;
}
if (current_value.length > max_len) {
display.style.fontSize = "1em";
} else {
display.style.fontSize = "2.5em";
}
display.textContent = current_value || "0";
});
});