Spaces:
Sleeping
Sleeping
File size: 1,371 Bytes
4c9277e |
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 |
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);
}
|