# Learn Basic OOP by Building a Shopping Cart - Step 24

**URL:** <https://forum.freecodecamp.org/t/learn-basic-oop-by-building-a-shopping-cart-step-24/664446>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [January 15, 2024, 7:26pm UTC](https://forum.freecodecamp.org/t/learn-basic-oop-by-building-a-shopping-cart-step-24/664446 "2024-01-15T19:26:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Addel-Ali](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/addel-ali/32/349263_2.png) [@Addel-Ali](https://forum.freecodecamp.org/u/Addel-Ali)\
**Post date:** [January 15, 2024, 7:26pm UTC](https://forum.freecodecamp.org/t/learn-basic-oop-by-building-a-shopping-cart-step-24/664446/1 "2024-01-15T19:26:32Z")

</div>

### Tell us what’s happening:

```auto
totalCountPerProduct[dessert.id] = (totalCountPerProduct[dessert.id])+1 || 0;
    });

```

I just need to know what I did wrong, so that the challange is not being passed

### Your code so far

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.

````plaintext
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 24

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/learn-basic-oop-by-building-a-shopping-cart/step-24)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![bbsmooth](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bbsmooth/32/203556_2.png) [@bbsmooth](https://forum.freecodecamp.org/u/bbsmooth)\
**Post date:** [January 15, 2024, 7:30pm UTC](https://forum.freecodecamp.org/t/learn-basic-oop-by-building-a-shopping-cart-step-24/664446/2 "2024-01-15T19:30:43Z")

</div>

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (').

---

<div class="post-metadata">

**Author:** ![bbsmooth](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bbsmooth/32/203556_2.png) [@bbsmooth](https://forum.freecodecamp.org/u/bbsmooth)\
**Post date:** [January 15, 2024, 7:36pm UTC](https://forum.freecodecamp.org/t/learn-basic-oop-by-building-a-shopping-cart-step-24/664446/3 "2024-01-15T19:36:59Z")

</div>

The hint I am getting for your code above is:

“You should wrap your right-hand `totalCountPerProduct[data.id]` in parentheses.”

Which is not useful as you are already wrapping `totalCountPerProduct[data.id]` in parentheses. So I can understand your confusion.

The problem you are trying to solve here is that `totalCountPerProduct[data.id]` could be `undefined`, and so in that case you want to use the value `0` instead. So inside the parentheses you either want to use the value of `totalCountPerProduct[data.id]` if it isn’t `undefined` **OR** the value `0`.

Hopefully that gives you enough of a hint as to how to solve this.

---

<div class="post-metadata">

**Author:** ![Addel-Ali](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/addel-ali/32/349263_2.png) [@Addel-Ali](https://forum.freecodecamp.org/u/Addel-Ali)\
**Post date:** [January 16, 2024, 4:37am UTC](https://forum.freecodecamp.org/t/learn-basic-oop-by-building-a-shopping-cart-step-24/664446/4 "2024-01-16T04:37:11Z")

</div>

Thanks for your help

---

<div class="post-metadata">

**Author:** ![Addel-Ali](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/addel-ali/32/349263_2.png) [@Addel-Ali](https://forum.freecodecamp.org/u/Addel-Ali)\
**Post date:** [January 16, 2024, 4:38am UTC](https://forum.freecodecamp.org/t/learn-basic-oop-by-building-a-shopping-cart-step-24/664446/5 "2024-01-16T04:38:12Z")

</div>

Still not getting it, what is the right(correct) syntax ?

---

<div class="post-metadata">

**Author:** ![bbsmooth](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bbsmooth/32/203556_2.png) [@bbsmooth](https://forum.freecodecamp.org/u/bbsmooth)\
**Post date:** [January 16, 2024, 4:39am UTC](https://forum.freecodecamp.org/t/learn-basic-oop-by-building-a-shopping-cart-step-24/664446/6 "2024-01-16T04:39:55Z")

</div>

Can you paste your updated code in here so we can see what you did? Remember to use the method outlined above to paste it in here properly.

---

<div class="post-metadata">

**Author:** ![Addel-Ali](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/addel-ali/32/349263_2.png) [@Addel-Ali](https://forum.freecodecamp.org/u/Addel-Ali)\
**Post date:** [January 16, 2024, 4:45am UTC](https://forum.freecodecamp.org/t/learn-basic-oop-by-building-a-shopping-cart-step-24/664446/7 "2024-01-16T04:45:23Z")

</div>

Matter of fact, I already solved the challange, understood that I had to state both facts and complete the expression.  
Thanks your help

---

<div class="post-metadata">

**Author:** ![klinzzyy](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/klinzzyy/32/352549_2.png) [@klinzzyy](https://forum.freecodecamp.org/u/klinzzyy)\
**Post date:** [February 9, 2024, 7:12pm UTC](https://forum.freecodecamp.org/t/learn-basic-oop-by-building-a-shopping-cart-step-24/664446/8 "2024-02-09T19:12:01Z")

</div>

You’ve saved my mental health lol, thank you

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [August 10, 2024, 7:12am UTC](https://forum.freecodecamp.org/t/learn-basic-oop-by-building-a-shopping-cart-step-24/664446/9 "2024-08-10T07:12:19Z")

</div>

Closed on August 10, 2024, 7:12am UTC

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