Skip to content

Commit 17d8d27

Browse files
Add random number generator (#54)
* Add random number generator * Add line break --------- Co-authored-by: Juliano Costa <[email protected]>
1 parent f9a9155 commit 17d8d27

File tree

5 files changed

+128
-0
lines changed

5 files changed

+128
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script src="{{ site.baseurl }}/assets/scripts/generate-random-numbers.js"></script>
2+
<div style="display: flex; flex-direction: column; align-items: center;">
3+
<div style="display: flex; flex-direction: row; gap: 24px;">
4+
<div class="input__wrapper field">
5+
<input type="number" class="input__field" placeholder="⬇️ Minimum Value" name="min" id='min' required />
6+
<label for="min" class="input__label">⬇️ Minimum Value</label>
7+
</div>
8+
9+
<div class="input__wrapper field">
10+
<input type="number" class="input__field" placeholder="⬆️ Maximum Value" name="max" id='max' required />
11+
<label for="max" class="input__label">⬆️ Maximum Value</label>
12+
</div>
13+
</div>
14+
<div class="input__wrapper field">
15+
<input type="number" class="input__field" placeholder="🔁 Spins" name="spins" id='spins' required />
16+
<label for="spins" class="input__label">🔁 Spins</label>
17+
</div>
18+
<button onclick="generateRandomNumbers()">🎲 Generate</button>
19+
<strong id="result-header"></strong>
20+
<p id="result"></p>
21+
</div>

_layouts/default.html

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ <h1 class="site-name"><a href="{{ site.baseurl }}/">{{ site.name }}</a></h1>
3535
<a href="{{ site.baseurl }}/speaker-info">Speaker Info</a>
3636
<a href="{{ site.baseurl }}/slides">Slides & Content</a>
3737
<a href="{{ site.baseurl }}/statistics">Events</a>
38+
<a href="{{ site.baseurl }}/random-number-generator">🎲</a>
3839
<!--
3940
<a href="{{ site.baseurl }}/search">Search</a>
4041
<a href="{{ site.baseurl }}/archive">Archive</a>

_pages/random-number-generator.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
layout: page
3+
title: Random Number Generator
4+
permalink: /random-number-generator/
5+
---
6+
7+
{% include random-number-generator.html %}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function generateRandomNumbers() {
2+
document.getElementById('result-header').innerText = '';
3+
document.getElementById('result').innerText = '';
4+
5+
const min = parseInt(document.getElementById('min').value, 10);
6+
const max = parseInt(document.getElementById('max').value, 10);
7+
const spins = parseInt(document.getElementById('spins').value, 10);
8+
9+
if (
10+
!min || isNaN(min) || min < 0 ||
11+
!max || isNaN(max) || max <= min ||
12+
!spins || isNaN(spins) || spins <= 0 || spins > max - min + 1
13+
) {
14+
document.getElementById('result-header').innerText = 'Invalid input';
15+
return
16+
}
17+
18+
19+
const generatedNumbers = new Set();
20+
while (generatedNumbers.size < spins) {
21+
const randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
22+
generatedNumbers.add(randomNumber);
23+
}
24+
25+
document.getElementById('result-header').innerText = 'Your lucky numbers are:';
26+
document.getElementById('result').innerText = Array.from(generatedNumbers).join(', ');
27+
}

assets/style.scss

+72
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,78 @@ p > img {
256256
clear: both;
257257
}
258258

259+
// Forms
260+
.input__wrapper {
261+
position: relative;
262+
padding: 16px 0 0;
263+
margin-top: 10px;
264+
}
265+
266+
.input__field {
267+
border: 0;
268+
border-bottom: 1px solid $gray;
269+
outline: 0;
270+
padding: 8px 0;
271+
background: transparent;
272+
transition: border-color 0.2s;
273+
font-size: 16px;
274+
275+
&::placeholder {
276+
color: transparent;
277+
}
278+
279+
&:placeholder-shown ~ .input__label {
280+
cursor: text;
281+
top: 20px;
282+
font-size: 16px;
283+
}
284+
}
285+
286+
.input__label {
287+
position: absolute;
288+
top: 0;
289+
display: block;
290+
transition: 0.2s;
291+
color: $gray;
292+
font-size: 10px;
293+
}
294+
295+
.input__field:focus {
296+
~ .input__label {
297+
position: absolute;
298+
top: 0;
299+
display: block;
300+
transition: 0.2s;
301+
color: $blue;
302+
font-weight: bold;
303+
font-size: 10px;
304+
}
305+
border-width: 3px;
306+
border-color: $blue;
307+
}
308+
309+
/* reset input */
310+
.input__field{
311+
&:required,&:invalid { box-shadow:none; }
312+
}
313+
314+
button {
315+
background-color: $white;
316+
border-radius: 8px;
317+
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
318+
319+
color: $blue;
320+
border: 1px solid $blue;
321+
padding: 6px 16px;
322+
margin: 24px;
323+
font-size: 18px;
324+
}
325+
326+
button:hover{
327+
background-color: $blue;
328+
color: $white;
329+
}
330+
259331
/*********************/
260332
/* LAYOUT / SECTIONS */
261333
/*********************/

0 commit comments

Comments
 (0)