-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (48 loc) · 1.81 KB
/
index.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
const menu = {
Starters: ["Garlic Bread", "Bruschetta"],
MainCourses: ["Margherita Pizza", "Spaghetti Carbonara"],
Desserts: ["Tiramisu", "Cheesecake"]
};
function displayMenuItems(menu) {
const menuContainer = document.getElementById("menu");
menuContainer.innerHTML = "";
for (const [category, items] of Object.entries(menu)) {
const categoryElement = document.createElement("h2");
categoryElement.textContent = category;
menuContainer.appendChild(categoryElement);
const listElement = document.createElement("ul");
items.forEach(item => {
const listItem = document.createElement("li");
listItem.textContent = item;
listItem.addEventListener('click', () => {
addToOrder(item);
});
listElement.appendChild(listItem);
});
menuContainer.appendChild(listElement);
}
};
function addToOrder(itemName) {
console.log(`${itemName} added to the order.`);
const orderItemsList = document.getElementById("order-items");
const orderTotalElement = document.getElementById("order-total");
const listItem = document.createElement("li");
listItem.textContent = itemName;
orderItemsList.appendChild(listItem);
const itemPrices = {
"Garlic Bread": 50,
"Bruschetta": 30,
"Margherita Pizza": 100,
"Spaghetti Carbonara": 80,
"Tiramisu": 55,
"Cheesecake": 45
};
const itemPrice = itemPrices[itemName] || 0;
let currentTotal = parseFloat(orderTotalElement.textContent.replace('Total: R', '')) || 0;
currentTotal += itemPrice;
orderTotalElement.textContent = `Total: R${currentTotal.toFixed(2)}`;
}
function initMenuSystem(menu) {
displayMenuItems(menu);
}
initMenuSystem(menu);