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
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.