Skip to content

Commit d3698e7

Browse files
committed
part of js
1 parent 0c51362 commit d3698e7

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"liveServer.settings.port": 5501
3+
}

checkout.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const taxRate = 0.18;
2+
const shippingPrice = 15.0;
3+
4+
window.addEventListener("load", () => {
5+
localStorage.setItem("taxRate", taxRate);
6+
localStorage.setItem("shippingPrice", shippingPrice);
7+
sessionStorage.setItem("taxRate", taxRate);
8+
sessionStorage.setItem("shippingPrice", shippingPrice);
9+
//add after func. coding
10+
calculateCartTotal()
11+
});
12+
13+
//capturing vs. bubbling
14+
let productsDiv = document.querySelector(".products");
15+
productsDiv.addEventListener("click", (e) => {
16+
//console.log(event.target);
17+
//minus buttons
18+
if (e.target.classList.contains("minus")) {
19+
// console.log("minusBtn clicked");
20+
if (e.target.nextElementSibling.innerText > 1) {
21+
// e.target.parentElement.lastElementChild.innerText;
22+
e.target.nextElementSibling.innerText--;
23+
//calculate Product and Cart Total
24+
//passing selectedProductInfo as parameter
25+
calculateProductAndCartTotal(e.target.parentElement.parentElement);
26+
}
27+
else {
28+
if (confirm("Product will be removed!")) {
29+
e.target.parentElement.parentElement.parentElement.remove();
30+
//calculateCartTotal
31+
calculateCartTotal();
32+
}
33+
}
34+
}
35+
36+
//plus buttons
37+
else if (e.target.className == "plus") {
38+
// console.log("plusBtn clicked");
39+
// e.target.parentElement.firstElementChild.innerText;
40+
e.target.previousElementSibling.innerText++;
41+
//calculate Product and Cart Total
42+
calculateProductAndCartTotal(e.target.parentElement.parentElement);
43+
}
44+
45+
//remove buttons
46+
else if (e.target.className == "remove-product") {
47+
// console.log("removeBtn clicked");
48+
if (confirm("Product will be removed")) {
49+
e.target.parentElement.parentElement.parentElement.remove();
50+
//calculateCartTotal
51+
calculateCartTotal()
52+
}
53+
54+
}
55+
//other elements
56+
else {
57+
console.log("other elements clicked");
58+
}
59+
})
60+
61+

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ <h2>Antique Clock</h2>
103103
</div>
104104
</div>
105105
</main>
106-
<script src="app.js"></script>
106+
<script src="checkout.js"></script>
107107
</body>
108108

109109
</html>

0 commit comments

Comments
 (0)