Food World - Home
Home
Welcome to our menu!
Explore our delicious options.
Fresh ingredients every day.
Explore our menu and enjoy authentic Indian cuisine.
Food World - About
About Us
Our passion for food.
Fresh and authentic flavors.
Serving with love.
We are passionate about serving authentic Indian cuisine with fresh ingredients.
Food World - Media
Media
Visual delights.
Photos and videos.
Customer favorites.
Our Menu
Chicken Curry
$10.00
Vegetable Biryani
$12.00
Fresh Salad
$8.00
View photos, videos, and reviews of our restaurant.
Food World - Contact
Contact
Reach out to us.
We'd love to hear from you.
Contact details below.
in each HTML page.
console.log("JS File Linked Successfully!");
// b. Select elements using selectors
// Select by ID (assuming an element with id="restaurant-title" exists in HTML)
const titleElement = document.getElementById("restaurant-title");
console.log("script.js:20 Selected by ID:", titleElement ? titleElement.textContent : "Not found");
// Select by Class (assuming an element with class="food-description" exists)
const classElement = document.getElementsByClassName("food-description")[0];
console.log("script.js:21 Selected by Class:", classElement ? classElement.textContent : "Not found");
// Select ALL with querySelectorAll (assuming paragraphs with class="para" exist)
console.log("script.js:23 Selected ALL with querySelectorAll:");
const paragraphs = document.querySelectorAll(".para");
paragraphs.forEach((para, index) => {
console.log(`script.js:25 Paragraph ${index + 1}: ${para.textContent}`);
});
// Select Button (assuming a button with id="sample-btn" exists)
const button = document.getElementById("sample-btn");
console.log("script.js:28 Selected Button:", button ? button.textContent : "Not found");
// c. Implement event listeners and d. Handle click events
if (button) {
button.addEventListener("click", function() {
alert("Select items and add address"); // Popup message for "Take Order"
});
}
// e. Demonstrate functions
// i. Function declaration
function greetDeclaration(name) {
return `Hello, ${name}! Welcome to Food World.`;
}
// ii. Function definition (expression)
const greetExpression = function(name) {
return `Hi, ${name}! Enjoy our spicy dishes.`;
};
// iii. Arrow function
const greetArrow = (name) => `Hey, ${name}! Our food is healthy and delicious.`;
// Call and log them (for demonstration)
console.log(greetDeclaration("Chef"));
console.log(greetExpression("Chef"));
console.log(greetArrow("Chef"));
// Cart functionality with localStorage persistence
let cart = JSON.parse(localStorage.getItem('foodWorldCart')) || []; // Load from storage or default to empty
function saveCart() {
localStorage.setItem('foodWorldCart', JSON.stringify(cart));
}
function addToCart(name, price) {
const existingItem = cart.find(item => item.name === name);
if (existingItem) {
existingItem.quantity += 1;
} else {
cart.push({ name, price, quantity: 1 });
}
saveCart(); // Save to storage
alert(`${name} added to cart!`);
updateCartDisplay();
}
function updateCartDisplay() {
const cartCount = cart.reduce((sum, item) => sum + item.quantity, 0);
const cartTotal = cart.reduce((sum, item) => sum + (item.price * item.quantity), 0);
// Update cart button text (if exists)
const cartBtn = document.getElementById("view-cart-btn");
if (cartBtn) {
cartBtn.textContent = `View Cart (${cartCount} items - $${cartTotal.toFixed(2)})`;
}
}
function showCart() {
let cartContent = "Your Cart:\n\n";
let total = 0;
if (cart.length === 0) {
cartContent = "Your cart is empty.";
} else {
cart.forEach(item => {
const itemTotal = item.price * item.quantity;
cartContent += `${item.name} (x${item.quantity}) - $${itemTotal.toFixed(2)}\n`;
total += itemTotal;
});
cartContent += `\nTotal: $${total.toFixed(2)}\n\nProceed to checkout?`;
}
if (confirm(cartContent)) {
alert("Thank you for your order! We'll deliver to the restaurant address.");
cart = []; // Clear cart
saveCart(); // Update storage
updateCartDisplay();
}
}
// Additional JS for carousel
function initCarousel() {
const images = document.querySelectorAll(".carousel img");
const prevBtn = document.getElementById("prev");
const nextBtn = document.getElementById("next");
let currentIndex = 0;
function showImage(index) {
images.forEach((img, i) => {
img.style.display = i === index ? "block" : "none";
img.classList.toggle("active", i === index);
});
// Update indicators
const dots = document.querySelectorAll(".dot");
dots.forEach((dot, i) => dot.classList.toggle("active", i === index));
}
showImage(currentIndex);
// Auto-rotate
setInterval(() => {
currentIndex = (currentIndex + 1) % images.length;
showImage(currentIndex);
}, 3000);
// Event listeners for buttons
prevBtn.addEventListener("click", () => {
currentIndex = (currentIndex - 1 + images.length) % images.length;
showImage(currentIndex);
});
nextBtn.addEventListener("click", () => {
currentIndex = (currentIndex + 1) % images.length;
showImage(currentIndex);
});
// Indicators click
const dots = document.querySelectorAll(".dot");
dots.forEach((dot, i) => {
dot.addEventListener("click", () => {
currentIndex = i;
showImage(currentIndex);
});
});
}
// Initialize on page load
document.addEventListener("DOMContentLoaded", () => {
initCarousel();
updateCartDisplay(); // Load and display cart on page load
// Add event listener for cart button
const cartBtn = document.getElementById("view-cart-btn");
if (cartBtn) {
cartBtn.addEventListener("click", showCart);
}
});