Learn Basic OOP by Building a Shopping Cart - Step 27

Tell us what’s happening:

Hello guys, I need your help. I don’t know what else to try in this exercise.

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);
    const { name, price } = product;
    this.items.push(product);

    const totalCountPerProduct = {};
    this.items.forEach((dessert) => {
      totalCountPerProduct[dessert.id] = (totalCountPerProduct[dessert.id] || 0) + 1;
    })

    const currentProductCount = totalCountPerProduct[product.id];
    const currentProductCountSpan = document.getElementById(`product-count-for-id${id}`);
    
   currentProductCount ? currentProductCount < 1 : undefined 
  }

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Learn Basic OOP by Building a Shopping Cart - Step 27

Hello there!
This is the base syntax for the ternary operator.

condition ? exprIfTrue : exprIfFalse

Your condition is not placed in the right place, also, the exprIfTrue and exprIfFalse, should take an undefined as their expressions.

So what would it be like? Something like that? currentProductCount < 1 ? undefined : undefined.?

Try that and see if you get any error or hint.

Use console.log() to check if your variables are what they should be

Hello thank you very much. I already got it. It was a small spelling mistake, so to speak. :sweat_smile: :sweat_smile:

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