-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
89 lines (76 loc) · 3.13 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Secret Santa Generator</title>
<!-- Bootstrap CDN -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
background-color: #f5f5f5;
}
#name-input,
#output {
margin-bottom: 20px;
}
#output {
font-size: 1.5em;
font-weight: bold;
cursor: pointer;
}
#output:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1 class="mb-4">Secret Santa Generator</h1>
<div id="name-input">
<div class="form-group">
<label for="participants">Enter Names of Participants (separated by commas):</label>
<input type="text" class="form-control" id="participants" placeholder="Name1, Name2, Name3...">
</div>
<button class="btn btn-primary" onclick="assignSecretSanta()">Assign Secret Santas</button>
</div>
<div id="output" class="text-danger"></div>
</div>
<script>
let names = [];
let shuffledNames = [];
let currentIndex = 0;
function assignSecretSanta() {
const input = document.getElementById('participants').value;
names = input.split(',').map(name => name.trim());
shuffledNames = [...names];
for (let i = shuffledNames.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffledNames[i], shuffledNames[j]] = [shuffledNames[j], shuffledNames[i]];
}
document.getElementById('name-input').style.display = 'none';
const output = document.getElementById('output');
output.style.display = 'block';
output.innerHTML = '<img src="https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/160/twitter/282/santa-claus_1f385.png" alt="Santa" width="50px" height="50px"> Click to reveal your Secret Santa!';
output.addEventListener('click', revealNextSecretSanta);
}
function revealNextSecretSanta() {
if (currentIndex < shuffledNames.length) {
let yourName = prompt('Enter your name:');
yourName = yourName ? yourName.trim() : '';
if (yourName === shuffledNames[currentIndex]) {
alert('You cannot get yourself as your Secret Santa.');
return;
}
document.getElementById('output').innerHTML = `<strong>Your Secret Santa is:</strong> ${shuffledNames[currentIndex]}`;
currentIndex++;
} else {
document.getElementById('output').innerHTML = '<strong>All Secret Santas have been revealed!</strong>';
document.getElementById('output').removeEventListener('click', revealNextSecretSanta);
}
}
</script>
</body>
</html>