var cart = []; var total=0; var totalamt=0; function removeFromCart(index) { var removedprice = cart[index].price; totalamt-=1; total-=removedprice; cart.splice(index, 1); updateCart(); } function addToCart(productName, price) { var item = { name: productName, price: price }; cart.push(item); } function printCart() { var cartItemsElement = document.getElementById('cart-items'); cartItemsElement.innerHTML = ''; var sum = 0; cart.forEach(function(item) { var listItem = document.createElement('li'); listItem.textContent = item.name + ' - $' + item.price; cartItemsElement.appendChild(listItem); sum += item.price; }); var listItem = document.createElement('li'); listItem.textContent =' - $' + sum; cartItemsElement.appendChild(listItem); } function runningTotal() { cart.forEach(function(item) { sum += item.price; }