Build an Inventory Management Program - Build an Inventory Management Program

Tell us what’s happening:

what am i doing wrong here? could not pass 8, 10 , 12, 14,15 and 16

Your code so far

let inventory = [{name: "flour", quantity: 5}, {name: "rice", quantity: 5}]; 

const findProductIndex = (productName) => {
productName = productName.toLowerCase();
let result = inventory.findIndex(obj => obj.name === productName);
if(result =>0)
return result;
else 
return -1;
}
let find = findProductIndex("floUr");
console.log(find);


const addProduct = (productName) => {
productName.name = productName.name.toLowerCase();  
let result = inventory.find(obj => obj.name === productName.name);  
if(result){
  result.quantity+=productName.quantity;
  return `${productName.name} quantity updated` ;
}
else {
  inventory.push(productName)
  return  `${productName.name} added to inventory` ;
}
}
console.log(addProduct({name: "floUr", quantity: 4}))

const removeProduct = (nam,quantity) => {
nam = nam.toLowerCase();  
let res = !inventory.some(obj => obj.name === nam);
let result = inventory.find(obj => obj.name === nam);
if(res){
  return `${nam} not found`;
}
else if(result.name.includes(nam) && result.quantity>quantity){
result.quantity-=quantity;
return `Remaining ${nam} pieces: ${result.quantity}`
}
else if (result.name.includes(nam) && result.quantity<quantity) {
 return `Not enough ${nam} available, remaining pieces: ${result.quantity}`
}
else{
  delete inventory.find(obj => obj.name === nam)
  return `${nam} not found`;
}
}
console.log(removeProduct("flour", 10))
// for (let i=0;i>inventory.length;i++){
//  if(inventory[i]=productName)
//  return inventory[i];

Your browser information:

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

Challenge Information:

Build an Inventory Management Program - Build an Inventory Management Program
https://www.freecodecamp.org/learn/full-stack-developer/lab-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.