-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.js
150 lines (123 loc) · 3.9 KB
/
cart.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
let price = document.getElementById("price");
const subBtn = document.getElementById("sub");
const addBtn = document.getElementById("add");
let input = document.getElementById("inputEl");
let inputOne = document.getElementById("inputElOne");
let inputTwo = document.getElementById("inputElTwo");
let inputThree = document.getElementById("inputElThree");
let firstPrice = document.getElementById("priceOne");
const subFirstBtn = document.getElementById("subOne");
const addFirstBtn = document.getElementById("addOne");
let secondPrice = document.getElementById("priceTwo");
const subSecondBtn = document.getElementById("subTwo");
const addSecondBtn = document.getElementById("addTwo");
let thirdPrice = document.getElementById("priceThree");
const subThirdBtn = document.getElementById("subThree");
const addThirdBtn = document.getElementById("addThree");
let totalOutcome = document.getElementById("total");
let conculsion = document.getElementById("order");
let count = 0,
countOne = 0,
countTwo = 0,
priceDetail = 0,
priceDetailOne = 0,
priceDetailTwo = 0;
subBtn.addEventListener("click", () => {
if (count < 1) {
return (count = 0);
}
count = count - 1;
input.textContent = count;
priceDetail -= 20;
price.textContent = priceDetail;
outPut();
});
addBtn.addEventListener("click", () => {
count = count + 1;
input.textContent = count;
priceDetail += 20;
price.textContent = priceDetail;
outPut();
});
subFirstBtn.addEventListener("click", () => {
if (countOne < 1) {
return (countOne = 0);
}
countOne = countOne - 1;
inputOne.textContent = countOne;
priceDetailOne -= 10;
firstPrice.textContent = priceDetailOne;
outPut();
});
addFirstBtn.addEventListener("click", () => {
countOne = countOne + 1;
inputOne.textContent = countOne;
priceDetailOne += 10;
firstPrice.textContent = priceDetailOne;
outPut();
});
subSecondBtn.addEventListener("click", () => {
if (countTwo < 1) {
return (countTwo = 0);
}
countTwo = countTwo - 1;
inputTwo.textContent = countTwo;
priceDetailTwo -= 25;
secondPrice.textContent = priceDetailTwo;
outPut();
});
addSecondBtn.addEventListener("click", () => {
countTwo = countTwo + 1;
inputTwo.textContent = countTwo;
priceDetailTwo += 25;
secondPrice.textContent = priceDetailTwo;
outPut();
});
let countThird = 0;
let priceDetailThree = 0;
subThirdBtn.addEventListener("click", () => {
if (countThird < 1) {
return (countThird = 0);
}
countThird = countThird - 1;
inputThree.textContent = countThird;
priceDetailThree -= 25;
thirdPrice.textContent = priceDetailThree;
outPut();
});
addThirdBtn.addEventListener("click", () => {
countThird = countThird + 1;
inputThree.textContent = countThird;
priceDetailThree += 25;
thirdPrice.textContent = priceDetailThree;
outPut();
});
const outPut = () => {
let fallBack =
+price.textContent +
+firstPrice.textContent +
+secondPrice.textContent +
+thirdPrice.textContent;
totalOutcome.textContent = fallBack;
// Used the unary operator to return value as integer from strings
};
let conclude = document.getElementById("orderConfirm");
conculsion.addEventListener("click", () => {
const bounceBack = totalOutcome.textContent;
if (bounceBack == 0) {
return conclude;
}
conculsion.innerHTML = "<p class='order'>Thank you for your order.</p>";
});
let promoCode = document.getElementById("promo");
let promoBtn = document.getElementById("btn");
let promoT = document.getElementById("promoText");
promoBtn.addEventListener("click", () => {
const promoInput = promoCode.value;
if (promoInput == "" || promoInput == undefined) {
return promoBtn;
}
promoT.innerHTML = "<p class='promoText'>Approved. Continue shopping</p>";
promoBtn += promoT.innerHTML;
promoCode.value = " ";
});