const Store = { cart: JSON.parse(localStorage.getItem('bbCart') || '[]') }; function renderCart() { const list = document.getElementById('cartList'); const empty = document.getElementById('cartEmpty'); const totalEl = document.getElementById('totalPrice'); const checkout = document.getElementById('checkoutBtn'); if (Store.cart.length === 0) { empty.classList.remove('hidden'); list.innerHTML = ''; totalEl.textContent = '$0.00'; checkout.disabled = true; return; } empty.classList.add('hidden'); checkout.disabled = false; let total = 0; list.innerHTML = Store.cart.map(item => { const sub = item.price * item.qty; total += sub; return `
${item.name}

${item.name}

$${item.price.toFixed(2)} each

${item.qty}
$${sub.toFixed(2)}
`; }).join(''); totalEl.textContent = `$${total.toFixed(2)}`; feather.replace(); } function changeQty(e) { const id = +e.currentTarget.dataset.id; const action = e.currentTarget.dataset.action; const item = Store.cart.find(i => i.id === id); if (action === 'inc') item.qty += 1; else { item.qty -= 1; if (item.qty <= 0) Store.cart = Store.cart.filter(i => i.id !== id); } localStorage.setItem('bbCart', JSON.stringify(Store.cart)); renderCart(); } document.addEventListener('click', e => { if (e.target.closest('.qty-btn')) changeQty(e); }); document.getElementById('checkoutBtn').addEventListener('click', () => { alert("Thanks! We'll start cooking and text you when it's ready."); Store.cart = []; localStorage.removeItem('bbCart'); renderCart(); }); renderCart();