-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (55 loc) · 2.23 KB
/
script.js
File metadata and controls
70 lines (55 loc) · 2.23 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
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
const discretePackage = (value) => {
document.getElementById("choice").innerText = value
}
function shuffle(array) {
let currentIndex = array.length, randomIndex;
// While there remain elements to shuffle...
while (currentIndex !== 0) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
// And swap it with the current element.
[array[currentIndex], array[randomIndex]] = [
array[randomIndex], array[currentIndex]];
}
return array;
}
document.getElementById('charCount').addEventListener('input', function() {
const count = parseInt(this.value);
const nameInputDiv = document.getElementById('nameInput');
nameInputDiv.innerHTML = ''; // Clear previous inputs
if (isNaN(count) || count < 1 || count > 26) {
// Do nothing or show an error
return;
}
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
for (let i = 0; i < count; i++) {
// Shuffle the letters array to get random order
const shuffledLetters = shuffle(letters.slice());
// Create select element
const select = document.createElement('select');
for (let j = 0; j < shuffledLetters.length; j++) {
const option = document.createElement('option');
option.value = shuffledLetters[j];
option.text = shuffledLetters[j];
select.appendChild(option);
}
nameInputDiv.appendChild(select);
}
});
document.getElementById('confirmButton').addEventListener('click', function() {
const selects = document.querySelectorAll('#nameInput select');
let name = '';
selects.forEach(function(select) {
name += select.value;
});
alert("Nå kan vi navnet ditt, takk skal du ha :) <3 :)")
const confirmedNameDiv = document.getElementById('confirmedName');
confirmedNameDiv.textContent = 'Confirmed Name: ' + name;
});
const displayInfo = () => {
adress = document.getElementById("adress").
name = document.getElementById("confirmedName")
discrete = document.getElementById("choice").innerText
alert(`Gratulerer ${name}. du har nå abbonert og får tilsendt til ${adress}. Diskret? ${discrete}`)
}