-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
203 lines (182 loc) · 6.9 KB
/
index.html
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html>
<head>
<title>Shopping Cart</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
/>
<link
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css"
rel="stylesheet"
/>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<section>
<div class="container">
<div class="cart">
<div class="col-md-12 col-lg-10 mx-auto">
<div class="cart-item">
<div class="row">
<div class="col-md-7 center-item">
<img src="images/product-1.png" alt="" />
<h5>iPhone 11 128GB Black</h5>
</div>
<div class="col-md-5 center-item">
<div class="input-group number-spinner">
<button id="removePhone" class="btn btn-default">
<i class="fas fa-minus"></i>
</button>
<input
id="noOfPhone"
type="text"
class="form-control text-center"
value="1"
/>
<button id="addPhone" class="btn btn-default">
<i class="fas fa-plus"></i>
</button>
</div>
<h5>$ <span id="phonePrice">1219</span></h5>
<img src="images/remove.png" alt="" class="remove-item" />
</div>
</div>
</div>
<div class="cart-item">
<div class="row">
<div class="col-md-7 center-item mx-auto">
<img src="images/product-2.png" alt="" />
<h5>iPhone 11 Silicone Case - Black</h5>
</div>
<div class="col-md-5 center-item">
<div class="input-group number-spinner">
<button id="removeCase" class="btn btn-default">
<i class="fas fa-minus"></i>
</button>
<input
id="noOfCase"
type="text"
class="form-control text-center"
value="1"
/>
<button id="addCase" class="btn btn-default">
<i class="fas fa-plus"></i>
</button>
</div>
<h5>$ <span id="casePrice">59</span></h5>
<img src="images/remove.png" alt="" class="remove-item" />
</div>
</div>
</div>
<div class="cart-item">
<div class="row">
<div class="col-md-8">
<h5>Subtotal:</h5>
<h5>Tax:</h5>
<h5>Total:</h5>
</div>
<div class="col-md-4 status">
<h5>$ <span id="subTotal">1278</span></h5>
<h5>$0</h5>
<h5>$ <span id="total">1278</span></h5>
</div>
</div>
</div>
<div class="col-md-12 pt-4 pb-4">
<button type="button" class="btn btn-success check-out">
Check Out
</button>
</div>
</div>
</div>
</div>
</section>
<script>
const singlePhonePrice = 1219;
const singleCasePrice = 59;
let subtotalPrice = parseFloat(
document.getElementById("subTotal").innerText
);
let totalPrice = parseFloat(document.getElementById("total").innerText);
//add new phone event handler
const addPhoneButton = document.getElementById("addPhone");
addPhoneButton.addEventListener("click", function () {
let noOfPhone = parseInt(document.getElementById("noOfPhone").value);
noOfPhone++;
document.getElementById("noOfPhone").value = noOfPhone;
PriceOfPhone(singlePhonePrice);
nitPhonePrice(singlePhonePrice);
});
//add new case event handler
const addCaseButton = document.getElementById("addCase");
addCaseButton.addEventListener("click", function () {
let noOfCase = parseInt(document.getElementById("noOfCase").value);
noOfCase++;
document.getElementById("noOfCase").value = noOfCase;
PriceOfCase(singleCasePrice);
nitCasePrice(singleCasePrice);
});
//remove phone event handler
const removePhoneButton = document.getElementById("removePhone");
removePhoneButton.addEventListener("click", function () {
let noOfPhone = parseInt(document.getElementById("noOfPhone").value);
if (noOfPhone > 0) {
noOfPhone--;
document.getElementById("noOfPhone").value = noOfPhone;
PriceOfPhone(-1 * singlePhonePrice);
nitPhonePrice(-1 * singlePhonePrice);
}
});
//remove case event handler
const removeCaseButton = document.getElementById("removeCase");
removeCaseButton.addEventListener("click", function () {
let noOfCase = parseInt(document.getElementById("noOfCase").value);
if (noOfCase > 0) {
noOfCase--;
document.getElementById("noOfCase").value = noOfCase;
PriceOfCase(-1 * singleCasePrice);
nitCasePrice(-1 * singleCasePrice);
}
});
//price of phone
function PriceOfPhone(singlePhone) {
let phonePrice = parseFloat(
document.getElementById("phonePrice").innerText
);
phonePrice = phonePrice + singlePhone;
document.getElementById("phonePrice").innerText = phonePrice;
return phonePrice;
}
//price of case
function PriceOfCase(singleCase) {
let casePrice = parseFloat(
document.getElementById("casePrice").innerText
);
casePrice = casePrice + singleCase;
document.getElementById("casePrice").innerText = casePrice;
return casePrice;
}
//total and subtotal Phone price
function nitPhonePrice(singlePhonePrice) {
subtotalPrice = subtotalPrice + singlePhonePrice;
document.getElementById("subTotal").innerText = subtotalPrice;
totalPrice = totalPrice + singlePhonePrice;
document.getElementById("total").innerText = totalPrice;
}
//total and subtotal Case price
function nitCasePrice(singleCasePrice) {
subtotalPrice = subtotalPrice + singleCasePrice;
document.getElementById("subTotal").innerText = subtotalPrice;
totalPrice = totalPrice + singleCasePrice;
document.getElementById("total").innerText = totalPrice;
}
let currentPhone = parseInt(noOfPhone.value);
if (currentPhone < 0) {
noOfPhone.value = 0;
}
</script>
</body>
</html>