-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.js
31 lines (26 loc) · 933 Bytes
/
code.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 btnSubmit = document.querySelector(".submit");
const thanksCard = document.getElementById("thanks");
const ratingCard = document.getElementById("card-rating");
const alertP = document.getElementById("alert");
const userRating = document.getElementById("user-value");
let clicked = false;
let valueRating = 0;
let buttonsRating = document.querySelectorAll(".btn-rating");
for (let i = 0; i < buttonsRating.length; i++) {
buttonsRating[i].addEventListener("click", function (e) {
valueRating = e.target.value;
clicked = true;
alertP.style.display = "none";
});
}
function submitRating() {
if (clicked) {
ratingCard.style.display = "none";
thanksCard.style.display = "block";
userRating.textContent = valueRating;
} else {
alertP.textContent = "Please choose between 1-5 in the buttons above. ";
alertP.style.display = "block";
}
}
btnSubmit.addEventListener("click", submitRating);