-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (23 loc) · 729 Bytes
/
Copy pathscript.js
File metadata and controls
28 lines (23 loc) · 729 Bytes
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
let cart = [];
let totalAmount = 0;
function addToCart(productName, price) {
cart.push({ name: productName, price: price });
totalAmount += price;
updateCart();
}
function updateCart() {
const cartItems = document.getElementById("cart-items");
cartItems.innerHTML = "";
cart.forEach(item => {
const li = document.createElement("li");
li.textContent = `${item.name} - $${item.price}`;
cartItems.appendChild(li);
});
document.getElementById("total").textContent = `Total: $${totalAmount}`;
}
function checkout() {
alert(`Thank you for your purchase! Your total is $${totalAmount}.`);
cart = [];
totalAmount = 0;
updateCart();
}