Build an Inventory Management Program - Build an Inventory Management Program

Tell us what’s happening:

I can’t pass the last two tests, a hint?

Your code so far



let inventory = [];
   
const findProductIndex = (productName) =>{

    return inventory.findIndex(ingredient => ingredient.name.toLowerCase() === productName.toLowerCase());

};


const addProduct = (product) =>{

const prodInInventory = findProductIndex(product.name)

if (prodInInventory !== -1){

inventory[prodInInventory].quantity += product.quantity;

console.log(product.name.toLowerCase()+" quantity updated");

} else { 

    inventory.push({name:product.name.toLowerCase(), quantity: product.quantity});

    console.log(product.name.toLowerCase()+" added to inventory"); 

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

const removeProduct  = (productName, prodQuantity) => {

let prodIndex = findProductIndex(productName);

if (prodIndex === -1){

  console.log(`${productName.toLowerCase()} not found`) 
}

if ((prodIndex !== -1)&&(inventory[prodIndex].quantity>=prodQuantity)){

inventory[prodIndex].quantity -= prodQuantity;

console.log(`Remaining ${productName.toLowerCase()} pieces: ${inventory[prodIndex].quantity}`)

} else if ((prodIndex !== -1)&&(inventory[prodIndex].quantity<=prodQuantity)) {

inventory.splice(prodIndex,1)

console.log(`Not enough ${productName.toLowerCase()} available, remaining pieces: ${inventory[prodIndex].quantity}`)

}
}

Your browser information:

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

Challenge Information:

Build an Inventory Management Program - Build an Inventory Management Program

Hi @vlad.salomont

Try calling the function call from user story 10.

Then the function call from user story 16.

Happy coding

MOD Solution removed  

thank you, this is my solution!

Hi @vlad.salomont

Congratulations on solving the challenge! You should be proud of your achievement…we are! But we are removing your working solution, so it is not available to others who have not yet done the work to get there. Again, congrats!

1 Like