Build an Inventory Management Program - Build an Inventory Management Program

Tell us what’s happening:

“You should declare an empty array named inventory”
This is the first test and only text I didn’t pass. But everything seems fine to me.

Your code so far

const inventory = [];

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

function addProduct(product) {
  let finalPro = {
    name: product.name.toLowerCase(),
    quantity: product.quantity
  }
for (let i = 0; i < inventory.length; i++) {
  if (inventory[i].name === finalPro.name) {
    console.log(inventory[i].name + " quantity updated");
    inventory[i].quantity = inventory[i].quantity + product.quantity;
    return

  }
} 
   console.log(finalPro.name + " added to inventory")
   inventory.push(finalPro);
 return
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36 Edg/150.0.0.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

Your solution works from my end. Please try one of the following steps to move forward.

Click on the “Restart Step” button and force a refresh of your page with CTRL + F5 then try to paste the code in again.

or - Try the step in incognito or private mode.

or - Disable any/all extensions that interface with the freeCodeCamp website (such as Dark Mode, Ad Blockers, or Spellcheckers), and set your browser zoom level to 100%. Both of these factors can cause tests to fail erroneously.

or - Ensure your browser is up-to-date or try a different browser.

I hope one of these will work for you.

incognito or private mode: didn’t work
disable all extensions(turning off dark mode): Worked!