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