Tell us what’s happening:
My code is not passing tests 13, 14, and 16, but when I compile my code elsewhere, it gives the results the tests are looking for, so I’m not sure what’s wrong
Your code so far
let inventory = [];
function findProductIndex(product) {
let searchTerm = product.toLowerCase();
let result = -1;
for (let i=0; i < inventory.length; i++) {
if (inventory[i].name === searchTerm) {
result = i;
}
}
return result;
}
function addProduct(object) {
let productName = object.name.toLowerCase();
for (let i=0; i < inventory.length; i++) {
if (productName == inventory[i].name) {
inventory[i].quantity += object.quantity;
console.log(`${productName} quantity updated`);
return;
}
}
inventory.push(
{
name: productName,
quantity: object.quantity
}
)
console.log(`${productName} added to inventory`)
}
function removeProduct(name, qty) {
let search = name.toLowerCase();
for (let i=0; i < inventory.length; i++) {
if (search === inventory[i].name && (inventory[i].quantity - qty) > 0) {
inventory[i].quantity -= qty;
console.log(`Remaining ${search} pieces: ${inventory[i].quantity}`);
return;
}
else if (search === inventory[i].name && (inventory[i].quantity - qty) == 0) {
inventory.splice(i, 1);
return;
}
else if (search === inventory[i].name && (inventory[i].quantity - qty) < 0) {
console.log(`Not enough ${search} available, remaining pieces: ${inventory[i].quantity}`);
return;
}
else if (search !== inventory[i].name) {
console.log(`${search} not found`);
return;
}
}
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:154.0) Gecko/20100101 Firefox/154.0
Challenge Information:
Build an Inventory Management Program - Build an Inventory Management Program