Build an Inventory Management System (test 13 specifically)

I have an issue with my removeProduct function passing test 13.
13. removeProduct("FLOUR", 5) should subtract 5 from the quantity value of the object having name equal to "flour" inside the inventory array.

Here is the code:

function removeProduct(itemName, itemCount) {
  let product = itemName.toLowerCase();
  let index = findProductIndex(itemName);

  if (index === -1) {
    console.log(`${product} not found`);
  } else if (index !== -1) {
    let currentCount = inventory[index].quantity;
    if (currentCount === itemCount) {
      inventory.splice(index, 1);
    } else if (itemCount > currentCount) {
      console.log(`Not enough ${product} available, remaining pieces: ${currentCount}`);
    } else {
      currentCount -= itemCount;
      console.log(`Remaining ${product} pieces: ${currentCount}`);
    }
  }
}

When I test the function with console.log() below:

inventory.push({name: "flour", quantity: 10});
inventory.push({name: "first", quantity: 10});
inventory.push({name: "second", quantity: 20});
inventory.push({name: "third", quantity: 30});

removeProduct("FLOUR", 5);
removeProduct("First", 5);
removeProduct("SEcond", 5);
removeProduct("THIrd", 5);

It logs:

Remaining flour pieces: 5
Remaining first pieces: 5
Remaining second pieces: 15
Remaining third pieces: 25

I don’t understand why it isn’t passing. Could someone help me?

can you share the link to the project please?

and can you share all your code please?

Link: https://www.freecodecamp.org/learn/full-stack-developer/lab-inventory-management-program/build-an-inventory-management-program

Full Code:

let inventory = [];


function findProductIndex(str){
  let index = inventory.findIndex(obj => obj.name === str.toLowerCase());
  return index;
}

function addProduct(obj) {
  let product = obj.name.toLowerCase();
  let index = inventory.findIndex(item => item.name === product);

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

function removeProduct(itemName, itemCount) {
  let product = itemName.toLowerCase();
  let index = findProductIndex(itemName);

  if (index === -1) {
    console.log(`${product} not found`);
  } else if (index !== -1) {
    let currentCount = inventory[index].quantity;
    if (currentCount === itemCount) {
      inventory.splice(index, 1);
    } else if (itemCount > currentCount) {
      console.log(`Not enough ${product} available, remaining pieces: ${currentCount}`);
    } else {
      currentCount -= itemCount;
      console.log(`Remaining ${product} pieces: ${currentCount}`);
    }
  }
}

inventory.push({name: "flour", quantity: 10});
inventory.push({name: "first", quantity: 10});
inventory.push({name: "second", quantity: 20});
inventory.push({name: "third", quantity: 30});

removeProduct("FLOUR", 5);
removeProduct("First", 5);
removeProduct("SEcond", 5);
removeProduct("THIrd", 5);

are you sure you are actually removing the pieces from Inventory?

if I check with

inventory.push({name: "flour", quantity: 10});
inventory.push({name: "first", quantity: 10});
inventory.push({name: "second", quantity: 20});
inventory.push({name: "third", quantity: 30});
console.log(inventory)
removeProduct("FLOUR", 5);
console.log(inventory)
removeProduct("First", 5);
console.log(inventory)
removeProduct("SEcond", 5);
console.log(inventory)
removeProduct("THIrd", 5);
console.log(inventory)

there is no change after each call

[ { name: 'flour', quantity: 10 },
  { name: 'first', quantity: 10 },
  { name: 'second', quantity: 20 },
  { name: 'third', quantity: 30 } ]
Remaining flour pieces: 5
[ { name: 'flour', quantity: 10 },
  { name: 'first', quantity: 10 },
  { name: 'second', quantity: 20 },
  { name: 'third', quantity: 30 } ]
Remaining first pieces: 5
[ { name: 'flour', quantity: 10 },
  { name: 'first', quantity: 10 },
  { name: 'second', quantity: 20 },
  { name: 'third', quantity: 30 } ]
Remaining second pieces: 15
[ { name: 'flour', quantity: 10 },
  { name: 'first', quantity: 10 },
  { name: 'second', quantity: 20 },
  { name: 'third', quantity: 30 } ]
Remaining third pieces: 25
[ { name: 'flour', quantity: 10 },
  { name: 'first', quantity: 10 },
  { name: 'second', quantity: 20 },
  { name: 'third', quantity: 30 } ]

I figured it out. I forgot that my currentCount was only a reference to the object and not the object itself. I have updated the code and passed, thanks!