Facing some issue during assignment of shopping cart in javaScript

getting confused how to add products from array

1 Like

Can you add more details to question here? What you’re trying to do and where it is not going as expected?

1 Like


here I have attached sample code.Please provide more details so that we can resolve your issues easily.

// Define the array of products
let products = [  { name: "Product 1", price: 10.99 },  { name: "Product 2", price: 24.99 },  { name: "Product 3", price: 6.99 }];

// Define the shopping cart
let cart = [];

// Identify the selected products and add them to the shopping cart
function addToCart(productIndex) {
  let selectedProduct = products[productIndex];

// Example usage
addToCart(0); // Adds the first product to the cart
addToCart(2); // Adds the third product to the cart
console.log(cart); // Displays the contents of the cart

1 Like

can u please connect with me on google meet

Please join this link at 2.00 pm