Learn Basic OOP by Building a Shopping Cart - Step 23

Tell us what’s happening:

In your forEach callback, you need to update the totalCountPerProduct object. Using the id of the current dessert as your property, update the value of the property to be the current value plus one. Do not use the addition assignment operator for this.

Can someone help me out with this the totalCountPerProduct is empty so why are we accessing the [dessert.id ] shouldnt this give us null.

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

  addItem(id, products) {
    const product = products.find((item) => item.id === id);
    const { name, price } = product;
    this.items.push(product);

    const totalCountPerProduct = {};
    this.items.forEach((dessert) => { 
      totalCountPerProduct[dessert.id];
      
    })
  }

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36

Challenge Information:

Learn Basic OOP by Building a Shopping Cart - Step 23

I think they will deal with this in a future step so continue and if you still have a question then come back and let us know.