Tell us what’s happening:
Please I’m stuck and I don’t know how to continue, every test pass successfully except for 15 and I don’t know how to remove from the original inventory… Splice doesn’t modify the original inventory aswell please how do I complete this challenge??
Your code so far
const inventory = []
function findProductIndex(pName){
let lowCase = pName.toLowerCase()
let index = inventory.findIndex((name) => name.name === lowCase)
return index
}
function addProduct(pName){
let lowCase = pName.name.toLowerCase()
let filter = inventory.filter((obj) => obj.name === lowCase)
let ven = findProductIndex(lowCase)
if(inventory[ven]){
inventory[ven].quantity += pName.quantity
console.log(`${lowCase} quantity updated`)
}else if(!inventory[ven]){
inventory.push({name : lowCase, quantity: pName.quantity})
console.log(`${lowCase} added to inventory`)
}
return inventory
}
function removeProduct(pName,quantity){
let lowCase = pName.toLowerCase()
let remove = findProductIndex(lowCase)
if(!inventory[remove]){
console.log(`${lowCase} not found`)
}
if(inventory[remove]){
if(inventory[remove].quantity === 0){
inventory.splice(remove, 1)
}if(inventory[remove].quantity !== 0 && inventory[remove].quantity < quantity){
console.log(`Not enough ${lowCase} available, remaining pieces: ${inventory[remove].quantity}`)
}else{
inventory[remove]. quantity -= quantity
console.log(`Remaining ${lowCase} pieces: ${inventory[remove].quantity}`)}
}
return inventory
}
console.log(removeProduct("FLOUR", 20))
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Mobile Safari/537.36
Challenge Information:
Build an Inventory Management Program - Build an Inventory Management Program