Build an Inventory Management Program - Steps 13, 14, 16

Tell us what’s happening:

My code is not passing tests 13, 14, and 16, but when I compile my code elsewhere, it gives the results the tests are looking for, so I’m not sure what’s wrong

Your code so far

let inventory = [];
function findProductIndex(product) {
  let searchTerm = product.toLowerCase();
  let result = -1;
  for (let i=0; i < inventory.length; i++) {
    if (inventory[i].name === searchTerm) {
      result = i;
    }
  }
  return result;
}

function addProduct(object) {
  let productName = object.name.toLowerCase();
  for (let i=0; i < inventory.length; i++) {
    if (productName == inventory[i].name) {
      inventory[i].quantity += object.quantity;
      console.log(`${productName} quantity updated`);
      return;
    }
  }
  inventory.push(
    {
      name: productName,
      quantity: object.quantity
    }
  )
  console.log(`${productName} added to inventory`)
}

function removeProduct(name, qty) {
  let search = name.toLowerCase();
  for (let i=0; i < inventory.length; i++) {
    if (search === inventory[i].name && (inventory[i].quantity - qty) > 0) {
      inventory[i].quantity -= qty;
      console.log(`Remaining ${search} pieces: ${inventory[i].quantity}`);
      return;
      }
      else if (search === inventory[i].name && (inventory[i].quantity - qty) == 0) {
        inventory.splice(i, 1);
        return;
      }
      else if (search === inventory[i].name && (inventory[i].quantity - qty) < 0) {
        console.log(`Not enough ${search} available, remaining pieces: ${inventory[i].quantity}`);
        return;
      }
      else if (search !== inventory[i].name) {
        console.log(`${search} not found`);
        return;
      }
  }
}

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:154.0) Gecko/20100101 Firefox/154.0

Challenge Information:

Build an Inventory Management Program - Build an Inventory Management Program

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-inventory-management-program/66d75dd0aa65a71600dc669b.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @thenerdybirdy

To help you debug, add the following code at the end of the editor:

addProduct({name: "FLOUR", quantity: 5})
addProduct({name: "rice", quantity: 5})

console.log(inventory);

removeProduct("flour", 2);
removeProduct("rice", 2);

console.log(inventory);

Happy coding