-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
98 lines (97 loc) · 4.03 KB
/
script.js
File metadata and controls
98 lines (97 loc) · 4.03 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
let selectedSeat = 0;
let seatLeft = 40;
let totalPrice = 0;
let discountPrice = 0;
let seats = document.querySelectorAll(".seat")
for(let index = 0 ; index < 40 ; index++){
seats[index].addEventListener('click', function(){
if(seats[index].classList.contains("seat-selected")){
return
}
if(selectedSeat === 4){
myfunc()
alert("You can't buy more than 4 tickets at a time.")
return
}
seats[index].classList.remove("seat-not-selected");
seats[index].classList.add("seat-selected");
seats[index].classList.add("cursor")
let seatName = seats[index].innerText
ticketList.insertAdjacentHTML('beforeend', `
<div class="flex justify-between">
<p>${seatName}</p>
<p>Economy</p>
<p>550</p>
</div>
`);
let seatIs = document.getElementById("seatSelected")
selectedSeat = selectedSeat + 1
let number = document.getElementById("number").value
if(selectedSeat >= 1 && number !== ''){
document.getElementById("nextBtn").removeAttribute("disabled")
document.getElementById("nextBtn").classList.remove("cursor-not-allowed")
}
if(selectedSeat === 4){
document.getElementById("apply").removeAttribute("disabled")
document.getElementById("apply").classList.remove("cursor-not-allowed")
}
seatIs.innerText = selectedSeat
seatLeft = seatLeft - 1
let seatRemain = document.getElementById("seatLeft")
seatRemain.innerText = seatLeft
totalPrice = totalPrice + 550;
document.getElementById('totalP').innerText = totalPrice
document.getElementById('finalPrice').innerText = totalPrice;
if(selectedSeat === 4){
seats[index].classList.add("cursor")
}
})
}
let apply = document.getElementById("apply")
apply.addEventListener("click", function(){
let input = document.getElementById("inputBtn")
let inputText = input.value
if(inputText === "NEW15"){
discountPrice = totalPrice * (15 / 100)
totalPrice = totalPrice - discountPrice
let discountedPrice = Math.floor(totalPrice)
document.getElementById("discount-section").classList.remove("hidden")
document.getElementById("discount-section").classList.add("flex")
document.getElementById("showDiscount").innerText = discountPrice
document.getElementById('finalPrice').innerText = discountedPrice
document.getElementById("coupon-container").classList.add("hidden")
document.getElementById("error").classList.add("hidden")
} else if(inputText === "Couple 20"){
discountPrice = totalPrice * (20 / 100)
totalPrice = totalPrice - discountPrice
let discountedPrice = Math.floor(totalPrice)
document.getElementById("discount-section").classList.remove("hidden")
document.getElementById("discount-section").classList.add("flex")
document.getElementById("showDiscount").innerText = discountPrice
document.getElementById('finalPrice').innerText = discountedPrice
document.getElementById("coupon-container").classList.add("hidden")
document.getElementById("error").classList.add("hidden")
} else{
document.getElementById("error").classList.remove("hidden")
}
})
function myfunc(){
if(selectedSeat === 4){
for(let index = 0 ; index < 40 ; index++){
seats[index].classList.add("cursor")
}
}
}
setInterval(() => {
let number = document.getElementById("number").value
if(selectedSeat >= 1 && number !== ''){
document.getElementById("nextBtn").removeAttribute("disabled")
document.getElementById("nextBtn").classList.remove("cursor-not-allowed")
}
}, 1000);
function showHidePopUp(){
let number = document.getElementById("number").value
if(selectedSeat >= 1 && number !== ''){
document.getElementById('popUp').classList.toggle("hidden")
}
}