Build a Shopping Cart - Step 18

Tell us what’s happening:

Not sure, what I am missing in the callback function.

I guess, the correct comparison condition is item[“id”] === id, because if I do not enclose the id within quotes the id will be translated to the variable (supplied as an argument of addItem function, which the callback function has access to) which in turn translates to something like item[12] === 12 ? .
However, neither
item[“id”] === id //this seems to work as an isolated code snippet.
nor
item[id] === id

works for me.

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
    )
  }
    
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:147.0) Gecko/20100101 Firefox/147.0

Challenge Information:

Build a Shopping Cart - Step 18

Try using dot notation to access the id property of item.

this maybe is a oversight of the test, can you think of an other way to write this?

but item[id] === id is not going to work because it will be evaluated like you say like item[12] === 12

Hi @ILM

Thanks for the response. I later realized that I should have simply tried item.id (where id is “key literal”). It worked. I could not think any other way more obvious than this. is there any/many other way ?

I also guess that this might be the oversight of the test.

Thanks @dhess . it worked with dot notation.

that’s the most straightforward way yes!

I created an issue for this