-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
31 lines (28 loc) · 901 Bytes
/
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
const btnDiv = document.querySelector("#btnDiv");
const buttons = btnDiv.querySelectorAll("button");
const submitBtn = document.querySelector("#btnSubmit");
const rating = document.querySelector("#rating");
const ratingPage = document.getElementById("rate-page");
const thankYouPage = document.getElementById("thank-you-page");
thankYouPage.style.display = "none";
let userRate = -1;
buttons.forEach((btn) =>
btn.addEventListener("click", (e) => {
buttons.forEach((btn) => {
btn.classList.remove("active");
});
btn.classList.toggle("active");
userRate = btn.innerText;
}),
);
submitBtn.addEventListener("click", (e) => {
e.preventDefault();
if (userRate <= 0) {
alert("Please select a number");
return;
}
ratingPage.style.display = "none";
rating.innerText = userRate;
thankYouPage.style.display = "block";
console.log(`You choose ${userRate}`);
});