var cart = JSON.parse(localStorage.getItem("cart")) ||[];
var container = document.getElementById("cart-container");
function displayCart(){
    container.innerHTML = "";

    if(cart.length === 0){
        container.innerHTML = "<h2>Your Cart Is Empty</h2>";
        return;
    }
    for(var i =  0; i <cart.length; i++){
        container.innerHTML +=`
        <div class="cart-item">
        
        <img src="${cart[i].image}" width="120">
        <h3>${cart[i].name}</h3>
        <p>${cart[i].price}</p>
        <button onclick="removeItem(${i})">Remove</button>
        <div>
        `;
    }
}
function removeItem(index){
    cart.splice(index,1);
    localStorage.setItem("cart",JSON.stringify(cart));
    displayCart();
}
displayCart();