I'm trying to delete a key value pair from shopping list

56 views Asked by At

everyone. I am trying to write a function that takes an item, looks through a current shopping cart(an object), checks if the item is in the cart, deletes it if true, and return "That item is not in your cart." if false. I have this so far.

var cart = {}

function removeFromCart(item){
var cartItems = Object.keys(cart)
for (var i=0; i<cartItems.length ; i++){
  if (cartItems[i]===item){
    delete cart.item
    return
    }
  else if (i === cartItems.length)  {
    console.log("That item is not in your cart.")
    }
  }
}
0

There are 0 answers