-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.js
57 lines (40 loc) · 1.68 KB
/
app.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(function(){
document.querySelector('.seats').addEventListener('click', selectSeat);
document.querySelector('#movies').addEventListener('change', getMoviePrice);
let output = document.querySelector('.prices-seats');
let moviePrice, pickedSeats, HTMLOutput;
function selectSeat(e) {
// ADD SELECT AND DESELECT SEAT
if(e.target.classList.contains('occupied')) {
e.target.classList.toggle('discolored');
}
else if(e.target.classList.contains('seat')) {
e.target.classList.toggle('selected');
}
// ADD TO AMOUNT OF SEAT SELECTED
let allSelectedSeats = document.querySelectorAll('.selected');
let seatArr = Array.from(allSelectedSeats);
seatArr.shift();
pickedSeats = seatArr.length;
DOMOutput();
}
// ADD TO TOTAL OF THE PRICES OF SELECTED SEATS
function getMoviePrice(e) {
// SET VALUE TO USE TO CALCULATE SEAT PRICES
moviePrice = e.target.value;
DOMOutput();
}
// DOM TEMPLATE OF THE OUTPUT
HTMLOutput = `You have Selected <span class="glow">0</span> seats which cost a total of $<span class="glow">0</span>.`;
output.innerHTML = HTMLOutput;
// CALCULATE TICKET PRICE AND PRINT TO DOM
function DOMOutput() {
if ( pickedSeats == undefined || pickedSeats == 0) {
pickedSeats = 0;
} else if(moviePrice == undefined) {
moviePrice = 0;
}
HTMLOutput = `You have Selected <span class="glow">${pickedSeats}</span> seats which cost a total of $<span class="glow">${pickedSeats * moviePrice}</span>.`;
output.innerHTML = HTMLOutput;
}
})();