-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.js
33 lines (29 loc) · 984 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
32
33
let seats = document.querySelector(".all-seats");
for (let i = 0; i < 59; i++) {
let randint = Math.floor(Math.random() * 2);
let booked = randint === 1 ? "booked" : "";
seats.insertAdjacentHTML(
"beforeend",
`<input type="checkbox" name="tickets" id="s${i + 2}"/>
<label for="s${i + 2}" class="seat ${booked}"></label>`
)
}
let tickets = seats.querySelectorAll("input");
tickets.forEach((ticket) => {
ticket.addEventListener("change", () => {
let amount = document.querySelector(".amount").innerHTML;
let count = document.querySelector(".count").innerHTML;
amount = Number(amount);
count = Number(count);
if (ticket.checked) {
count += 1;
amount += 200;
}
else {
count -= 1;
amount -= 200;
}
document.querySelector(".amount").innerHTML = amount;
document.querySelector(".count").innerHTML = count;
})
})