-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
37 lines (28 loc) · 896 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
34
35
const seats = document.querySelectorAll(".seat");
const pelicula = document.getElementById("pelicula");
const count = document.getElementById("count");
const total = document.getElementById("total");
let price = parseInt(pelicula.value);
let seatsSelected = 0;
function selectSeat(seat) {
length = seat.classList.length;
if (length === 1) {
seat.classList.add("selected");
seatsSelected++;
}
else if (length === 2) {
seat.classList.remove("selected");
seatsSelected--;
}
count.innerText = seatsSelected;
total.innerText = (price * seatsSelected);
}
seats.forEach(seat => {
if (seat.classList != "seat occupied") {
seat.addEventListener("click", () => { selectSeat(seat) })
}
});
pelicula.addEventListener("change", () => {
price = parseInt(pelicula.value);
total.innerText = (price * seatsSelected);
})