How to put the cards in container


@dharshini-ta-fsr

@dhanuchougule41
To put the cards in the container, you can call the createCard function inside the forEach loop, passing each product object as an argument to the createCard function.

Please refer to the following code and try.If you have any other doubts means you can ask.

const container = document.getElementById(containerId);

products.forEach((product) => {
  // create card for each product
  const card = createCard(product);
  // put this card in container
  container.appendChild(card);
});

function createCard(productInfo) {
  // create card element
  const card = document.createElement("div");

  // create image element
  const image = document.createElement("img");
  image.src = productInfo.imageSrc;

  // create name element
  const name = document.createElement("h3");
  name.textContent = productInfo.name;

  // create brand name element
  const brandName = document.createElement("h3");
  brandName.textContent = productInfo.brandName;

  // create price element
  const price = document.createElement("h3");
  price.textContent = productInfo.price;

  // append elements to card element
  card.appendChild(image);
  card.appendChild(name);
  card.appendChild(brandName);
  card.appendChild(price);

  // return the card element
  return card;
}

can please give me your linkdin id so can connect with

@dhanuchougule41 Sure!
https://www.linkedin.com/in/dharshini-m-056843210/