Tell us what’s happening:
I do not understand why my addProduct function is not passing, can anybody help please…
Your code so far
const inventory = [];
const findProductIndex = (productName) =>{
for(let i =0; i < inventory.length; i++){
if(inventory[i].name.toLowerCase() === productName.toLowerCase() ){
return i
}
}
return -1
}
console.log(findProductIndex("lol"))
const addProduct = (productObject) =>
{
let found = false;
for(let i = 0; i < inventory.length; i++){
if( productObject.name.toLowerCase()
=== inventory[i].name.toLowerCase())
{
inventory[i].quantity = inventory[i].quantity + productObject.quantity;
console.log(`${productObject.name} quantity updated`);
found = true;
}
}if(found === false){
inventory.push(productObject);
console.log(`${productObject.name} added to inventory`)
}
}
console.log(addProduct({name: "FLOUR", quantity: 5},
))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Challenge Information:
Build an Inventory Management Program - Build an Inventory Management Program