Tell us what’s happening:
Frustrated…
I can’t even tell you what the problem is now - I have been trying and trying and mutilated my code to the point that I really don’t even remember my original code anymore. I keep going back to what is being asked for me to do and it seems clear but maybe I am interpreting it wrong. I have looked at W3 schools and the other big JS reference sites but their explanations are sometimes geared only to people with degrees in computer science - which is great - but don’t help those of us who do not.
So I’m not going to put my code here because it’s not even the original code I wrote that was wrong (I have been stuck on this step for two days now).
So my main question is: can someone explain destructuring syntax?
In my opinion freeCodeCamp has not done a very complete job of explaining how it works at this point in the curriculum. I think that if I understand the syntax better (especially as it relates to this particular step) I should be able to solve it. (I’m not trying to be critical here, I’m just trying to be honest).
My assumptions this far:
- When the console says use dot notation to access the id property of dessert, it means this:
dessert.id
- When the console says use bracket notation to access the dessert.id property of the totalCountPerProduct object, I’m guessing it means this:
totalCountPerProduct{dessert.id}
or this:
totalCountPerProduct[dessert.id]
- I know I am trying to increment the totalCountPerProduct of the dessert product in this step, so to me this looks something like this:
items.forEach((dessert) => {
totalCountPerProduct{dessert.id += 1}
};
But, I know this is wrong.
Additional questions:
1.Why does my console keep giving me errors:
i: [Reference error: Cannot find variable: shopping cart] x4
ii: Unexpected token, where the unexpected token occurs at the “t” in total in the line of code:
const totalCountPerProduct = {}; ???
iii: Use dot notation for dessert.id, and bracket notation for totalCountPerProduct, even when I do use dot and bracket notation?
- Why does this step seem to contradict itself with the instructions saying do not use the addition assignment operator, and the console saying literally: " You should update the value of totalCountPerProduct to be the current value plus one."
Any clarification on this point would be extremely helpful and appreciated.
PS: Why is there always an unexpected token on line 82 (or some other line by the bounds of code) when there is literally nothing at all there?
Your code so far
<!-- file: index.html -->
/* 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) => {
dessert.id{totalCountPerProduct += 1
});
// User Editable Region
/* file: styles.css */
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 23