Tell us what’s happening:
Currently, I am unable to pass the 13th test for this lab. All the other tests pass, however, this one is not able to pass. Here’s a little bit of my code:
Your code so far
let inventory = [];
function findProductIndex(name){
const normalizedName = name.toLowerCase();
for(let i = 0; i < inventory.length; i++){
if(inventory[i].name === normalizedName) {
return i;
}
}
return -1;
}
function addProduct(obj){
if(findProductIndex(obj.name) >= 0){
inventory[findProductIndex(obj.name)].quantity += obj.quantity;
console.log(`${obj.name.toLowerCase()} quantity updated`);
} else {
let normalizedName = obj.name.toLowerCase();
obj.name = normalizedName;
inventory.push(obj);
console.log(`${obj.name} added to inventory`);
}
}
function removeProduct(name, quantity){
const index = findProductIndex(name);
if(index === -1){
console.log(`${name.toLowerCase()} not found`);
return;
}
if(index >= 0){
if(inventory[index].quantity < quantity){
console.log(`Not enough ${name.toLowerCase()} available, remaining pieces: ${inventory[index].quantity}`)
}
if(inventory[index].quantity > quantity){
inventory[index].quantity -= quantity;
console.log(`Remaining ${name.toLowerCase()} pieces: ${inventory[index].quantity}`);
}
if(inventory[index].quantity - quantity === 0){
inventory[index].quantity -= quantity;
inventory.splice(index, 1);
}
}
}
removeProduct("FLOUR", 5)
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36
Challenge Information:
Build an Inventory Management Program - Build an Inventory Management Program