Tell us what’s happening:
the code is working but i keep getting undefined after calling the function
Your code so far
let inventory = [];
function findProductIndex(productName) {
// Convert the product name to lowercase for case-insensitive comparison
const lowerCaseProductName = productName.toLowerCase();
// Use findIndex to search the inventory array for a matching product
return inventory.findIndex(
(product) => product.name.toLowerCase() === lowerCaseProductName
);
}
function addProduct(product) {
const productIndex = findProductIndex(product.name);
if (productIndex !== -1) {
inventory[productIndex].quantity += product.quantity;
console.log(`${product.name} quantity updated`)
} else {
inventory.push(product);
console.log(`${product.name} added to inventory`);
}
}
console.log(addProduct({name: "FLOUR", quantity: 5}));
console.log(addProduct({name: "FLOUR", quantity: 5}));
console.log(inventory)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Challenge Information:
Build an Inventory Management Program - Build an Inventory Management Program