-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
119 lines (109 loc) · 2.71 KB
/
script.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
let cartDisplay = 0;
function addItem(event) {
quantityDisplayEl.textContent = event.target.value;
}
const displayquantity = document.querySelector(".quantityItems");
function addToCart() {
cartDisplay = cartDisplay + 1;
displayquantity.textContent = cartDisplay;
}
const cartIcon = document.querySelector(".cart");
const shoppingCart = document.querySelector(".cartTab");
const closingButton = document.querySelector(".close");
const listCart = document.querySelector(".listCart");
cartIcon.addEventListener("click", function () {
shoppingCart.classList.add("open");
});
closingButton.addEventListener("click", function () {
shoppingCart.classList.remove("open");
});
const displayItems = document.querySelectorAll(".cart-button");
displayItems.forEach((button) => {
button.addEventListener("click", addToCart);
});
// Add event listeners for quantity controls
const minusButton = document.querySelector(".minus");
const plusButton = document.querySelector(".plus");
const number = document.querySelector(".number");
let itemNumber = 1;
// Need to comment this if using for loop way of displaying products in show cart tab
// plus button eventlisteners
plusButton.addEventListener("click", () => {
itemNumber++;
itemNumber = itemNumber < 10 ? +itemNumber : itemNumber;
number.innerHTML = itemNumber;
console.log(itemNumber);
});
// plus button eventlisteners
minusButton.addEventListener("click", () => {
itemNumber--;
itemNumber = itemNumber > 10 ? -itemNumber : itemNumber;
number.innerHTML = itemNumber;
console.log(itemNumber);
});
// untill here
// Products Array(not on my website)
const displayItemsInShoppingCart = [];
const cartItems = [
{
id: 1,
item: "Donuts",
price: 4,
quantity: 5,
Image: "images/doughnuts-donuts.webp",
},
{
id: 2,
item: "Muffins",
price: 5,
quantity: 1,
Image: "images/muffin.webp",
},
{
id: 3,
item: "Bread",
price: 6,
quantity: 5,
Image: "images/breads.jpg",
},
{
id: 4,
item: "Milkshakes",
price: 10,
quantity: 5,
Image: "images/milkshake.webp",
},
{
id: 5,
item: "Crossiants",
price: 8,
quantity: 5,
Image: "images/Croissants-01.jpg",
},
{
id: 6,
item: "Macarons",
price: 7,
quantity: 5,
Image: "images/macarons.avif",
},
{
id: 7,
item: "Sandwich",
price: 7,
quantity: 5,
Image: "images/Egg-Salad-Sandwich.jpg",
},
{
id: 8,
item: "Cookies",
price: 7,
quantity: 1,
Image: "images/miso_cookies.jpg",
},
];
// second way of adding product names to shopping cart
// for (let i = 0; i < cartItems.length; i++) {
// cartItems[i].item;
// listCart.innerHTML = cartItems[i].item + "\n" + listCart.innerHTML;
// }