-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (33 loc) · 1.18 KB
/
script.js
File metadata and controls
38 lines (33 loc) · 1.18 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
const button = document.querySelector(".submit-button");
const grades = document.querySelectorAll(".grades");
const mainPage = document.querySelector(".component-container");
const thankPage = document.querySelector(".thank-you");
const valorationText = document.querySelector(".valoration");
let valoration = 0;
const handleClick = (event) => {
event.preventDefault();
const grade = event.target;
valoration = grade.textContent;
grade.style.backgroundColor = "hsl(25, 97%, 53%)";
grade.style.color = "hsl(0, 0%, 100%)";
setDefault(event);
};
const setDefault = (event) => {
const father = event.target.parentElement;
Array.from(father.children).forEach((child) => {
if (child.textContent !== valoration) {
child.style.backgroundColor = "hsla(213, 19%, 23%, 0.88)";
child.style.color = "hsl(216, 12%, 54%)";
}
});
};
const handleSubmit = (event) => {
if (valoration === 0) return;
mainPage.classList.add("hidden");
thankPage.classList.remove("hidden");
valorationText.innerHTML = `You selected ${valoration} out of 5`;
};
Array.from(grades).forEach((grade) => {
grade.addEventListener("click", handleClick);
});
button.addEventListener("click", handleSubmit);