Undefined is always the response in the chrom console when console.log(cartItem) or console.log(id) why

getBagButtons() {

const buttons = […document.querySelectorAll(".bag-btn")];

buttonDOM = buttons;

buttons.forEach(button => {

let id = button.dataset.id;

let inCart = cart.find(item => item.id === id);

if (inCart) {

  button.innerText = "In Cart";

  button.disabled = true;

}  

  button.addEventListener("click", event => {

    // disable button

    event.target.innerText = "In Cart";

    event.target.disabled = true;

    let cartItem = { ...Storage.getProduct(id), amount: 1 };

    console.log(cartItem);

});

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