Hi everyone, I’ve been following this tutorial on how to make a shopping cart with JS and I’ve run into an issue.
When trying to access the array of products and find the objects that have a matching id with the products already in the cart (so I can access the rest of the object’s properties that are not available in the cart) I get undefined from the .find method.
This is step is shown around 2:23.00 in the tutorial.
The code is uploaded to a repo and the function I’m referring to starts at line 131 of the main.js file.
I’ve been trying to find where the problem is for a while now but can’t figure it out so any help is appreciated.
The tutorial uses shopsItemsData.find
You wrote productsData.find
Maybe it is the issue, maybe it is not.
We don’t know if you followed code from tutorial precisely. Or maybe you made some modifications in your own version.
That’s why I don’t use video coursess too often. Issues like that is kind of hard to deal with. Going through some video course myself right now - cool material, but it is not easy to follow along.
Edit. Or maybe I just do not have skills how to learn via video.
Thanks for the reply, I did change some of the variables’ names, they aren’t called all the same as in the tutorial, but I believe they are all consistent throughout the project so that is not the cause of the issue as far as I can tell
console.log(id) before the following line of code, you will see that
id is not a number like 104 or 105, it is something like product104 or product104. That is why the
find method is not capturing anything.
Omg, I literally just found this a minute ago as well and was ready to delete the post. I can’t believe I missed that. Crazy what coming back fresh can do lol
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.