Build an Inventory Management Program - Build an Inventory Management Program

Tell us what’s happening:

I am lost i tryed to fixit on my own but i dont know what could be the problem. The code is working fine but it is not pass the return steps.: [3,4,5, 7,8,9,10, 12,13,14,15,16].

Your code so far

const inventory = [];

function findProductIndex(productName, inventory) {
  const lowerCaseName = productName.toLowerCase();

  for (let i = 0; i < inventory.length; i++) {
    if (inventory[i].name.toLowerCase() === lowerCaseName) {
      return i;
    }
  }
  return -1;
}

function addProduct(productName, quantity, inventory) {
  const productIndex = findProductIndex(productName, inventory);

  if (productIndex !== -1) {
    inventory[productIndex].quantity += quantity;
    console.log(`${productName.toLowerCase()} quantity updated: ${inventory[productIndex].quantity}`);
  } else {
    inventory.push({ name: productName.toLowerCase(), quantity: quantity });
    console.log(`${productName.toLowerCase()} added to inventory with quantity: ${quantity}`);
  }
}

function removeProduct(productName, quantity, inventory) {
  const productIndex = findProductIndex(productName, inventory);
  const lowerCaseName = productName.toLowerCase();

  if (productIndex === -1) {
    return `${lowerCaseName} not found`;
  }
  const currentQuantity = inventory[productIndex].quantity;

  if (currentQuantity < quantity) {
    return `Not enough ${lowerCaseName} available, remaining pieces: ${currentQuantity}`;
  } else {
    inventory[productIndex].quantity -= quantity;
    const remaining = inventory[productIndex].quantity;

    if (remaining === 0) {
      inventory.splice(productIndex, 1);
    }
    return `Remaining ${lowerCaseName} pieces: ${remaining}`;
  }
}

console.log(findProductIndex("Flour", inventory));
addProduct("banana", 5, inventory);
addProduct("fLouR", 5, inventory);
console.log(findProductIndex("FloUr", inventory));

console.log(findProductIndex("flour", inventory));

console.log(removeProduct("FLOUR", 4, inventory));
console.log(removeProduct("FLOUR", 5, inventory));
console.log(removeProduct("flour", 1, inventory));
console.log(removeProduct("FLOUR", 5, inventory));

Your browser information:

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

Challenge Information:

Build an Inventory Management Program - Build an Inventory Management Program

All of your function definitions are incorrect because you are passing in a parameter that way not asked in the instructions.

That was the problem ty