Build a Shopping Cart - Step 29

Tell us what’s happening:

hello help me fix my code im getting the following msg i dont know whats wrong

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;
    })

  currentProductCount > 1 
      ? currentProductCountSpan.textContent = `${currentProductCount}x`
      : productsContainer.innerHTML += `
      <div id="dessert${id}" class="product">
      </div>
      `;
  }

// 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/134.0.0.0 Safari/537.36

Challenge Information:

Build a Shopping Cart - Step 29

wht message are you getting? you forgot to share that

anyway, you deleted part of the code, now currentProductCount does not exist anymore. You should see an error in the console saying something like that

// running tests 1. You should remove the

undefined

from your falsy expression. 2. You should use the addition assignment operator to add HTML to the

productsContainer

. Remember that HTML goes in the

innerHTML

property. 4. You should add a

div

to the

productsContainer

. 5. Your

div

should have the

class

set to

product

. 6. Your

div

should have the

id

set to

dessert${id}

. // tests completed // console output [ReferenceError: ShoppingCart is not defined] [ReferenceError: ShoppingCart is not defined] [ReferenceError: ShoppingCart is not defined] [ReferenceError: ShoppingCart is not defined] [ReferenceError: ShoppingCart is not defined] this is what im getting maybe im doing something wrong

have you changed your code since the first post? if not you are still missing various lines

currentProductCount > 1
? currentProductCountSpan.textContent = ${currentProductCount}x
: productsContainer.innerHTML += `

  </div>`    this is my  code currently and this is the error showing      1. You should remove the undefined from your falsy expression.
  1. You should use the addition assignment operator to add HTML to the productsContainer. Remember that HTML goes in the innerHTML property.
  2. You should add a div to the productsContainer.
  3. Your div should have the class set to product.
  4. Your div should have the id set to dessert${id}.
    // tests completed
    // console output
    [ReferenceError: ShoppingCart is not defined]
    [ReferenceError: ShoppingCart is not defined]
    [ReferenceError: ShoppingCart is not defined]
    [ReferenceError: ShoppingCart is not defined]
    [ReferenceError: ShoppingCart is not defined]

you are missing lines
you need to reset the step

1 Like

thanks it worked i used the if statement to update the count then used div inside template literals