Build an Inventory Management Program - Build an Inventory Management Program

Tell us what’s happening:

I’m not able to pass the 14 test case. please help. in the inventory management Program

Your code so far

let inventory = [];
   
const findProductIndex = (productName) =>{
    return inventory.findIndex(product => product.name.toLowerCase() === productName.toLowerCase());
}

const addProduct = (productObj) =>{
    const productIndex = findProductIndex(productObj.name.toLowerCase());
    if(productIndex === -1){
        inventory.push({name: productObj.name.toLowerCase(), quantity: productObj.quantity});
        console.log(`${productObj.name.toLowerCase()} added to inventory`);
    }else{
        inventory[productIndex].quantity += productObj.quantity;
        console.log(`${productObj.name.toLowerCase()} quantity updated`)
    }
}

const removeProduct = (productName, quantity) =>{
    const productIndex = findProductIndex(productName.toLowerCase());
    if(productIndex === -1){
        console.log(`${productName.toLowerCase()} not found`);
    }else{
        let remainingQuantity = inventory[productIndex].quantity -= quantity;
        if(remainingQuantity === 0){
            inventory.splice(productIndex, 1);
            ;
        }else if(remainingQuantity < 0){
          inventory[productIndex].quantity += quantity;
          console.log(`Not enough ${productName.toLowerCase()} available, remaining pieces: ${inventory[productIndex].quantity}`)
        }
        else if(remainingQuantity > 0){
          console.log(`Remaining flour pieces: ${inventory[productIndex].quantity}`)
        }
    }
};

inventory = [{name: "flour", quantity: 20}, {name: "rice", quantity: 5}]
removeProduct("FLOUR", 5)
console.log("Remaining flour pieces: 15")


Your browser information:

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

Challenge Information:

Build an Inventory Management Program - Build an Inventory Management Program

add this code below yours to test

inventory.length = 0;
inventory.push({name: 'flour', quantity: 15});
inventory.push({name: 'rice', quantity: 10});
inventory.push({name: 'sugar', quantity: 5});
removeProduct("Flour", 5);
removeProduct("RICE", 5);
removeProduct("Sugar", 2);

don’t you see something strange in the things logged to the console?

it worked thank you very much.