-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (26 loc) · 1002 Bytes
/
Copy pathscript.js
File metadata and controls
30 lines (26 loc) · 1002 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
29
30
const menuList = document.getElementById("menu-list");
const orderItems = document.getElementById("order-items");
const totalPrice = document.getElementById("total-price");
const menuItems = [
{ name: "Burger", price: 10 },
{ name: "Pizza", price: 12 },
{ name: "Salad", price: 8 },
// Add more menu items here
];
menuItems.forEach(item => {
const menuItem = document.createElement("div");
menuItem.className = "menu-item";
menuItem.innerHTML = `
<h3>${item.name}</h3>
<p>$${item.price}</p>
<button class="add-to-order">Add to Order</button>
`;
menuList.appendChild(menuItem);
menuItem.querySelector(".add-to-order").addEventListener("click", () => {
const orderItem = document.createElement("li");
orderItem.textContent = `${item.name} - $${item.price}`;
orderItems.appendChild(orderItem);
const currentTotal = parseFloat(totalPrice.textContent.replace("Total: $", ""));
totalPrice.textContent = `Total: $${currentTotal + item.price}`;
});
});