Build an Inventory Management Program - Build an Inventory Management Program

Tell us what’s happening:

My addProduct function is not passing the tests even though the output is correct on the console. Please assist and advise what I am missing out on.

Your code so far

const inventory = [];

function findProductIndex(product) {
  let index = inventory.findIndex(item => item.name.toLowerCase() === product.toLowerCase());
  return index;
}

function addProduct(product) {
  let {name, quantity} = product;
  const index = findProductIndex(product);
  product.name = name.toLowerCase();
  if (index === -1) {
    inventory.push(product);
    console.log(`${product.name} added to inventory`);
  }
  else {
    inventory[index].quantity += quantity;
    console.log(`${product.name} quantity updated`);
  }
}

Your browser information:

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

Challenge Information:

Build an Inventory Management Program - Build an Inventory Management Program

Have you double-checked your findProductIndex method as it’s being used by the addProduct method?

2 Likes