diff --git a/menu.js b/menu.js index 25fde170..f8c1497a 100644 --- a/menu.js +++ b/menu.js @@ -8,9 +8,16 @@ document.addEventListener('DOMContentLoaded', function () { var itemName = item.querySelector('h3').textContent; var itemPrice = item.querySelector('p').textContent; alert("Item added to cart successfully"); + + // Retrieve existing cart items from localStorage + var cartItems = JSON.parse(localStorage.getItem('cartItems')) || []; + + // Add new item to the cart array + var newItem = { name: itemName, price: itemPrice }; + cartItems.push(newItem); - localStorage.setItem('itemName', itemName); - localStorage.setItem('itemPrice', itemPrice); + // Save updated cart back to localStorage + localStorage.setItem('cartItems', JSON.stringify(cartItems)); window.location.href = "cart.html"; }