Build an Inventory Management Program - Build an Inventory Management Program

Tell us what’s happening:

hi
why I can’t pass test number 12?(Build an Inventory Management Program)

Your code so far

let inventory = [];  

function findProductIndex(productName) {  
    return inventory.findIndex(product => product.name.toLowerCase() === productName.toLowerCase());  
}  
  
function addProduct(product) {  

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

function removeProduct(productName, productQuantity) {  
    productName = productName.toLowerCase()
    const index = findProductIndex(productName);  
    if(index === -1) {  
        console.log(`${productName} not found.`);  
        return;  
    }  
    if(inventory[index].quantity < productQuantity) {  
        console.log(`Not enough ${productName} available, remaining pieces: ${inventory[index].quantity}`);  
    } else if(inventory[index].quantity === productQuantity) {  
        inventory.splice(index, 1); 
//        console.log(`Remaining ${productName} pieces: ${0}`);
        return console.log(`${productName} not found`);
    } else {  
        inventory[index].quantity -= productQuantity; // Decrease the quantity  
        console.log(`Remaining ${productName} pieces: ${inventory[index].quantity}`);  
    }  
}  
 
addProduct({name: "FLOUR", quantity: 5});
removeProduct("FLOUR", 5);

Your browser information:

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

Challenge Information:

Build an Inventory Management Program - Build an Inventory Management Program

It doesn’t pass because you are logging flour not found., while it asks for flour not found

Thank you very much for your answer. I hope I understood what you meant. I changed my code to ask if the product exists or not but it still doesn’t work?
//my code

let inventory = [];  

function findProductIndex(productName) {  
    return inventory.findIndex(product => product.name.toLowerCase() === productName.toLowerCase());  
}  
  
function addProduct(product) {  

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

function removeProduct(productName, productQuantity) {  
    productName = productName.toLowerCase()
    const index = findProductIndex(productName);  

    if(findProductIndex(productName) !== -1 ) {    
    
        if(inventory[index].quantity < productQuantity) {  
            console.log(`Not enough ${productName} available, remaining pieces: ${inventory[index].quantity}`);  
        } else if(inventory[index].quantity === productQuantity) {  
            inventory.splice(index, 1); 
//          console.log(`Remaining ${productName} pieces: ${0}`);
//          return console.log(`${productName} not found`);
        } else {  
        inventory[index].quantity -= productQuantity; // Decrease the quantity  
        console.log(`Remaining ${productName} pieces: ${inventory[index].quantity}`);  
        }
    
    }
    if(findProductIndex(productName) === -1 ) {
        console.log(`${productName} not found.`);
    }
}  
addProduct({name: "FLOUR", quantity: 5});
removeProduct("FLOUR", 5);
console.log(inventory);

I am not checking your code, I only see that you did not address the issue

Do you see the difference?
You are logging flour not found., but the expected string is flour not found

let’s put them one above the other:

flour not found.
flour not found

the first is yours, the second one is the correct one
please see the difference