-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
129 lines (110 loc) · 2.62 KB
/
index.html
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
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html>
<head>
<title>FoodPanda Clone</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<header>
<h1>FoodPanda Clone</h1>
</header>
<section id="restaurants">
<h2>Available Restaurants</h2>
<ul id="restaurant-list"></ul>
</section>
<section id="menu">
<h2>Menu</h2>
<ul id="menu-list"></ul>
</section>
<section id="cart">
<h2>Cart</h2>
<ul id="cart-items"></ul>
<p id="total-price">Total Price: $0</p>
<button id="checkout-btn">Checkout</button>
</section>
<script src="script.js"></script>
</body>
</html>
<style>
CSS (style.css):
css
Copy code
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #f2f2f2;
padding: 20px;
}
#restaurants, #menu, #cart {
margin: 20px;
}
h2 {
margin-top: 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
margin-bottom: 10px;
}
#total-price {
font-weight: bold;
}
#checkout-btn {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
<script>
JavaScript (script.js):
javascript
Copy code
document.addEventListener("DOMContentLoaded", function() {
const restaurantList = document.getElementById("restaurant-list");
const menuList = document.getElementById("menu-list");
const cartItems = document.getElementById("cart-items");
const totalPrice = document.getElementById("total-price");
const checkoutBtn = document.getElementById("checkout-btn");
const restaurants = [
{ id: 1, name: "Restaurant 1" },
{ id: 2, name: "Restaurant 2" },
{ id: 3, name: "Restaurant 3" }
];
const menu = [
{ id: 1, name: "Item 1", price: 10 },
{ id: 2, name: "Item 2", price: 15 },
{ id: 3, name: "Item 3", price: 8 }
];
let cart = [];
function renderRestaurantList() {
restaurantList.innerHTML = "";
for (const restaurant of restaurants) {
const li = document.createElement("li");
li.innerText = restaurant.name;
li.addEventListener("click", function() {
renderMenu(restaurant.id);
});
restaurantList.appendChild(li);
}
}
function renderMenu(restaurantId) {
menuList.innerHTML = "";
for (const item of menu) {
const li = document.createElement("li");
li.innerText = `${item.name} - $${item.price}`;
li.addEventListener("click", function() {
addToCart(item);
});
menuList.appendChild(li);
}
}
function addToCart
</script>