Build an Inventory Management Program - Build an Inventory Management Program

Tell us what’s happening:

guys i need help from 14-16 test, i have no idea what’s wrong with my code

Your code so far

let inventory = [];
inventory[0] = { name: 'flour', quantity: 20 };
inventory[1] = { name: 'rice', quantity: 2 };
let empty = [];


function findProductIndex(product) {
  let lowerCase = product.toLowerCase();
  for (let i = 0; i < inventory.length; i++) {
    if (inventory[i].name === lowerCase) {
      return inventory.indexOf(inventory[i]);
    }
  }
  for (let i = 0; i < inventory.length; i++) {
    if (inventory[i].name !== lowerCase) {
      return -1;
    }
  }
}
console.log(findProductIndex('flou'));

function addProduct(product) {
  let lowerCase = product.name.toLowerCase();
  for (let i = 0; i < inventory.length; i++) {
    if (inventory[i].name === lowerCase) {
      inventory[i].quantity = inventory[i].quantity + product.quantity;
      console.log(`${inventory[i].name} quantity updated`);
    }
  }
  for (let i = 0; i < inventory.length; i++) {
    for (let x of inventory[i].name.split(' ')) {
      empty.push(x);
    }
  }
  if (!empty.includes(lowerCase)) {
    product.name = lowerCase;
    inventory.push(product);
    console.log(`${lowerCase} added to inventory`)
  }
}
console.log(addProduct({ name: "FLour", quantity: 0 }))



function removeProduct(product, quantity) {
  let lowerCase = product.toLowerCase();
  for (let i = 0; i < inventory.length; i++) {

    if (lowerCase === inventory[i].name) {
      inventory[i].quantity = inventory[i].quantity - quantity;
      console.log(`Remaining ${inventory[i].name} pieces: ${inventory[i].quantity}`);
      if (inventory[i].quantity < quantity) {
        console.log(`Not enough ${inventory[i].name} available, remaining pieces: ${inventory[i].quantity}`)
      }
    }
    if (inventory[i].quantity === 0) {
      delete inventory[i];
    }
  }
  if (!empty.includes(lowerCase)) {
    console.log(`${lowerCase} not found`)
  }

}
console.log(removeProduct("FLoUR", 20))

Your browser information:

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

Challenge Information:

Build an Inventory Management Program - Build an Inventory Management Program

Here are some troubleshooting steps you can follow. Focus on one test at a time:

  1. Are there any errors or messages in the console?
  2. What is the requirement of the first failing test?
  3. Check the related User Story and ensure it’s followed precisely.
  4. What line of code implements this?
  5. What is the result of the code and does it match the requirement? (Write the value of a variable to the console at that point in the code if needed.)

If this does not help you solve the problem, please reply with answers to these questions.

i followed all the instructions, even the output is accurate as i see

i try my best but still fails

try answering the questions written by pkdvalis one by one. But I would also make sure you are not using console.log more than necessary