DynamicMenu / static /script.js
dschandra's picture
Create script.js
4c9277e verified
raw
history blame
1.37 kB
document.querySelectorAll('.add-button, .food-image').forEach(item => {
item.addEventListener('click', function () {
const foodItem = this.dataset.item;
showModal(foodItem);
});
});
function showModal(foodItem) {
const modal = document.getElementById('suggestion-modal');
document.getElementById('selected-item').innerText = foodItem;
const suggestions = getSuggestions(foodItem);
const suggestionList = document.getElementById('suggestion-list');
suggestionList.innerHTML = suggestions.map(item => `<li>${item}</li>`).join('');
modal.style.display = 'flex';
document.querySelector('.close-button').addEventListener('click', () => {
modal.style.display = 'none';
});
document.getElementById('add-to-cart-button').addEventListener('click', () => {
addToCart(foodItem, suggestions);
modal.style.display = 'none';
});
}
function getSuggestions(foodItem) {
const suggestionData = {
'Veg Samosa': ['Green Chutney', 'Masala Tea'],
'Onion Pakoda': ['Tamarind Sauce', 'Hot Tea'],
// Add more combinations here
};
return suggestionData[foodItem] || [];
}
let cart = [];
function addToCart(foodItem, suggestions) {
const quantity = document.getElementById('quantity').value;
cart.push({ foodItem, quantity, suggestions });
alert(`Added to cart: ${foodItem} (x${quantity})`);
console.log('Cart:', cart);
}