-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
280 lines (249 loc) · 7.58 KB
/
index.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<!DOCTYPE html>
<html>
<head>
<title>Envelope Selector</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
/>
<style>
body {
font-family: Arial, sans-serif;
/* background-color: #f4f4f4; */
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background: linear-gradient(
to right,
#2e689f,
#c3fef7,
#1d1b27,
#365f83
);
background-size: 400% 400%;
/* animation: gradientBackground 15s ease infinite; */
}
@keyframes gradientBackground {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
.container {
background-color: #ffffffa8;
padding: 20px;
border-radius: 25px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
max-width: 850px;
}
h1 {
margin-top: 0;
text-align: center;
}
.description {
font-size: 14px;
margin-bottom: 20px;
}
.envelope-container {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
margin-bottom: 20px;
}
.envelope {
width: 120px;
height: 80px;
background-color: #eee;
border: 2px solid #999;
border-radius: 25px;
display: flex;
justify-content: center;
align-items: center;
margin: 10px;
cursor: pointer;
transition: background-color 0.3s ease-in-out;
font-size: 16px;
font-weight: bold;
}
.envelope:hover {
background-color: #f0f0f0;
}
.chosen {
background-color: #00ff00;
}
.input-container {
margin-left: 18px;
}
.input-container label {
display: block;
margin-right: 10px;
font-size: 14px;
margin-bottom: 8px;
font-weight: bold;
text-align: left;
}
.input-container input {
width: 185px;
padding: 8px;
font-size: 16px;
border: 1px solid #999;
border-radius: 5px;
}
.random-button {
padding: 6px;
background-color: #4caf50;
border: none;
border-radius: 50%;
cursor: pointer;
position: relative;
}
.random-button .tooltip {
visibility: hidden;
background-color: #00000083;
color: #fff;
text-align: center;
border-radius: 5px;
padding: 5px;
position: absolute;
bottom: 125%;
left: 50%;
transform: translateX(-50%);
white-space: nowrap;
z-index: 1;
}
.random-button:hover .tooltip {
visibility: visible;
}
.random-button i {
color: #fff;
}
.error {
color: red;
margin: 5px 0;
text-align: left;
font-size: 12px;
height: 14px;
}
.submit-btn {
padding: 8px 16px;
font-size: 14px;
background-color: #4caf50;
color: #fff;
border: none;
border-radius: 50px;
cursor: pointer;
/* margin-bottom: 12px;
margin-left: 18px; */
margin: 0 0 12px 18px;
}
.submit-btn:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<h1>Envelope Selector!</h1>
<div class="input-container">
<p class="description">
Welcome to the Envelope Selector! This interactive tool allows you to
divide a given amount into a combination of envelopes, each
representing a specific monetary value. The envelope amounts are based
on the concept of binary numbers.
</p>
<p class="description">
Binary numbers are a fundamental building block of computer science
and digital systems. In the envelope selector, each envelope amount is
a power of 2, starting from $1 and doubling with each subsequent
envelope. This unique distribution of amounts enables you to create
any desired sum between $1 and $1000 without needing to switch money
between envelopes.
</p>
<p class="description">
To use the envelope selector, simply enter an amount between $1 and
$1000 in the input field. The tool will calculate and highlight the
envelopes you need to select to achieve the desired amount. You can
give any combination of envelopes to match the requested sum,
utilizing the power of binary representation.
</p>
<p class="description">
Have fun exploring the Envelope Selector and discovering the
fascinating world of binary numbers!
</p>
<label for="amount">Enter an amount between 1 to 1000:</label>
<input type="number" id="amount" min="1" max="1000" />
<button class="random-button" onclick="generateRandomAmount()">
<i class="fas fa-random"></i>
<span class="tooltip">Generate Random Amount</span>
</button>
<div id="error" class="error"></div>
</div>
<button id="submitBtn" class="submit-btn" onclick="suggestEnvelopes()">
Submit
</button>
<div class="envelope-container">
<div class="envelope" id="envelope1">$1</div>
<div class="envelope" id="envelope2">$2</div>
<div class="envelope" id="envelope3">$4</div>
<div class="envelope" id="envelope4">$8</div>
<div class="envelope" id="envelope5">$16</div>
<div class="envelope" id="envelope6">$32</div>
<div class="envelope" id="envelope7">$64</div>
<div class="envelope" id="envelope8">$128</div>
<div class="envelope" id="envelope9">$256</div>
<div class="envelope" id="envelope10">$489</div>
</div>
</div>
</body>
<script>
const amountInput = document.getElementById("amount")
const submitBtn = document.getElementById("submitBtn")
amountInput.addEventListener("keypress", function (event) {
// Check if Enter key is pressed (key code 13)
if (event.keyCode === 13 || event.which === 13) {
// Trigger click event on the submit button
submitBtn.click()
}
})
function suggestEnvelopes() {
const envelopes = [1, 2, 4, 8, 16, 32, 64, 128, 256, 489]
const chosenEnvelopes = []
const amount = parseInt(document.getElementById("amount").value)
if (amount > 1000) {
document.getElementById("error").innerHTML =
"Amount should not exceed 1000."
return
} else {
document.getElementById("error").innerHTML = ""
}
let remainingAmount = amount
for (let i = envelopes.length - 1; i >= 0; i--) {
if (remainingAmount >= envelopes[i]) {
chosenEnvelopes.push(i + 1)
remainingAmount -= envelopes[i]
}
}
for (let i = 1; i <= 10; i++) {
const envelope = document.getElementById(`envelope${i}`)
if (chosenEnvelopes.includes(i)) {
envelope.classList.add("chosen")
} else {
envelope.classList.remove("chosen")
}
}
}
function generateRandomAmount() {
const randomAmount = Math.floor(Math.random() * 1000) + 1
document.getElementById("amount").value = randomAmount
}
</script>
</html>