-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
80 lines (66 loc) · 2.63 KB
/
script.js
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
document
.getElementById("nameForm")
.addEventListener("submit", function (event) {
event.preventDefault();
const studentName = document.getElementById("studentName").value.trim();
const greetingElement = document.getElementById("greeting");
if (studentName) {
const currentHour = new Date().getHours();
let timeOfDay;
if (currentHour < 12) {
timeOfDay = "Good morning";
} else if (currentHour < 16) {
timeOfDay = "Good afternoon";
} else {
timeOfDay = "Good evening";
}
// Clear previous content
greetingElement.textContent = "";
// Create and append a new h2 element to avoid using innerHTML - warning given to us by codacy
const h2Element = document.createElement("h2");
h2Element.textContent = `${timeOfDay}, ${studentName}! Welcome to Creative Coder Jed's Class 🎉`;
greetingElement.appendChild(h2Element);
greetingElement.style.display = "block";
// Show banner and program section
document.getElementById("banner").style.display = "block";
document.getElementById("programSection").style.display = "block";
} else {
greetingElement.textContent = ""; // Clear previous content
const h4Element = document.createElement("h4");
h4Element.textContent = "Please enter your name to proceed.";
h4Element.style.color = "red";
greetingElement.appendChild(h4Element);
greetingElement.style.display = "block";
}
});
document
.getElementById("programForm")
.addEventListener("submit", function (event) {
event.preventDefault();
const checkboxes = document.querySelectorAll(
'input[name="program"]:checked'
);
const selectedPrograms = [];
checkboxes.forEach((checkbox) => {
selectedPrograms.push(checkbox.value);
});
const messageElement = document.getElementById("message");
if (selectedPrograms.length > 0) {
messageElement.textContent = ""; // Clear previous content
// Create text and strong elements to append
const strongElement = document.createElement("strong");
strongElement.textContent = selectedPrograms.join(", ");
// Append the message in a secure way
const messageText = document.createTextNode(
"Awesome choice! You're going to excel in: "
);
messageElement.appendChild(messageText);
messageElement.appendChild(strongElement);
messageElement.appendChild(
document.createTextNode(". Now, let's dive in! 💪")
);
} else {
messageElement.textContent =
"You need to select at least one program! Passion and hard work await.";
}
});