Tell us what’s happening:
The instructions seem Vague.
Your code so far
this.items.forEach((dessert) => {
totalCountPerProduct[id] = dessert.id
})
WARNING
The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.
You will need to take an additional step here so the code you wrote presents in an easy to read format.
Please copy/paste all the editor code showing in the challenge from where you just linked.
Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Challenge Information:
Learn Basic OOP by Building a Shopping Cart - Step 23
“Using the id
of the current dessert
as your property…”
This means that you should use the id
property of the current dessert
object that the callback is working on for the property name you want to update in totalCountPerProduct
. In your code above, you are using id
by itself, which won’t work because you haven’t defined a variable named id
. The id
is a property name on the current dessert
object.
“…update the value of the property to be the current value plus one. Do not use the addition assignment operator for this.”
This means they want you to increase the value of the property by 1
“the old-fashioned” way. If I gave you the following:
let total = 5;
And asked you to increase the value of total
by 1
on a separate line only using exactly one =
and one +
operator, how would you do that? That’s what you want to do in this callback.
1 Like
The dessert id part is going directily into the brackets = the same again + 1 || 0 . This is tricky because you have to assign the current value to totalCountPerProduct which is the same value Inside parenthese.
I came looking for answers as the instructions are vauge. Leaving info here for anyone with the same issue. I cracked it once I realised the intended outcome is this:
totalCountPerProduct = {
desset.id: count,
desset.id: count,
desset.id: count,
}
Where everytime the addItem function is run, the count for the corresponding dessert.id is updated by +1.
As you would expect a shopping basket to work.