Learn Basic OOP by Building a Shopping Cart - Step 23

Tell us what’s happening:

I don’t understand : " You should use bracket notation to access the property of totalCountPerProduct that corresponds to dessert.id." ??

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 = {id:dessert.id+1};
    })
  }

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36

Challenge Information:

Learn Basic OOP by Building a Shopping Cart - Step 23

Hi Sơn,

const object = {
    property: value;
    property_1: value_1;    
    property_2: value_2;    
}

An object has pairs of property - value.
And we can access those values by using bracket notion:

object[property]

Now, the instruction asked us to

update the totalCountPerProduct object

with:

  • property: Using the id of the current dessert as your property,
  • value: update the value of the property to be the current value plus one
5 Likes

Ok… I solved . tks again !

1 Like