Learn Basic OOP by Building a Shopping Cart - Step 18

Tell us what’s happening:

I’m trying to check equality with the id property of the function and the id property of item but it’s telling me that I’m doing something wrong. I don’t know what.

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

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15

Challenge Information:

Learn Basic OOP by Building a Shopping Cart - Step 18

returns whether the id property of item is strictly equal to the id

What do you mean by id.addItem?

1 Like

I’ve just been playing around with ways of identifying the parameter that’s supposed to be measured. addItem.id hasn’t been working.

addItem is a method, id is one of its parameters.

Inside find compare item.id to the id parameter.


Example
const users = [
  { id: 1, name: "John", age: 34 },
  { id: 2, name: "Amy", age: 20 },
];

const findUser = (id, users) => users.find((user) => user.id === id);

const user1 = findUser(1, users);
console.log(user1); // { id: 1, name: 'John', age: 34 }

const user2 = findUser(2, users);
console.log(user2); // { id: 2, name: 'Amy', age: 20 }
3 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.