-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidex.html
171 lines (141 loc) · 4.39 KB
/
idex.html
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> calculator </title>
<link rel="stylesheet" href="./style.css">
<style>@import url('https://fonts.googleapis.com/css?family=Montserrat&display=swap');
body {
background: #dde1e7;
font-family: 'Montserrat', sans-serif;
}
.container {
background: #dde1e7;
width: 320px;
height: 550px;
border-radius: .5em;
box-shadow: -3px -3px 7px #ffffff73,
2px 2px 5px rgba(94, 104, 121, 0.288);
margin: 0 auto;
padding: 32px 16px;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.container .result {
width: 100%;
height: 150px;
box-shadow: inset 2px 2px 5px #babecc,
inset -5px -5px 10px #ffffff73;
}
.container .result p {
font-size: 40pt;
overflow-y: auto;
text-align: right;
}
.container .buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 1em;
}
.container .buttons .button, .container .buttons .num-button {
cursor: grab;
text-align: center;
width: 60px;
font-size:18px;
height: 60px;
display: grid;
place-content: center;
border-radius: 50%;
box-shadow: 2px 2px 5px #babecc,
-5px -5px 10px #ffffff73;
}
.button:hover{
color: #55db34;
}
/* UTILITIES*/
.container .buttons .zero {
grid-column: 1/ 3;
width: 100%;
font-size:18px;
border-radius: 10px;
box-shadow: 2px 2px 5px #babecc,
-5px -5px 10px #ffffff73;
}
.action-btn {
color: grey;
font-weight: bold;
}
.calc-action-btn{
color: #ed11d7;
font-size: 20px;
font-weight: bold;
}</style>
</head>
<body>
<!-- partial:index.partial.html -->
<div class="container">
<div class="result">
<p id="result-box">0</p>
</div>
<div class="buttons">
<div class="button action-btn" id="clear"> AC </div>
<div class="button action-btn"> MC</div>
<div class="button num-button action-btn"> %</div>
<div class="button num-button calc-action-btn"> /</div>
<div class="button num-button seven">7</div>
<div class="button num-button eight">8</div>
<div class="button num-button nine">9</div>
<div class="button num-button calc-action-btn">*</div>
<div class="button num-button four">4</div>
<div class="button num-button five">5</div>
<div class="button num-button six">6</div>
<div class="button num-button calc-action-btn">-</div>
<div class="button num-button one">1</div>
<div class="button num-button two">2</div>
<div class="button num-button three">3</div>
<div class="button num-button calc-action-btn">+</div>
<div class="button num-button zero">0</div>
<div class="button num-button point">.</div>
<div class="button calc-action-btn" id="total">=</div>
</div>
</div>
<!-- partial -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/3.1.1/gsap.min.js'></script>
<script src="./script.js"></script>
<script>
let btns = document.querySelectorAll(".num-button");
let allBtns = document.querySelectorAll(".button");
let resultBox = document.querySelector("#result-box");
let clearBtn = document.querySelector('#clear');
let total = document.querySelector("#total");
let btnSpread = [...btns];
let allBtnSpread = [...allBtns];
// For Number Inputs
btnSpread.forEach((button, i) => {
button.addEventListener("click", () => {
// Inner Values for calculator
if (resultBox.innerHTML == "0") {
resultBox.innerHTML = "";
}
let value = btns[i].innerHTML;
resultBox.innerHTML += value;
});
});
// Function to evalute Strings
function evaluate(fn) {
return new Function('return ' + fn)();
}
// To calculate All Input
total.addEventListener('click', ()=> {
let allInputs = resultBox.innerHTML;
resultBox.innerHTML = evaluate(allInputs);
console.log(evaluate(allInputs));
})
// Clear all Inputs
clearBtn.addEventListener('click', ()=> {
resultBox.innerHTML = "0";
})
</script>
</body>
</html>