Tell us what’s happening:
When I run the tests 12, 14, and 16 aren’t passing and I’m not sure where the issue is because it seems to be outputting what it is supposed to.
Your code so far
const inventory = []
const findProductIndex = (product) => inventory.findIndex(item => item.name === product.toLowerCase());
const addProduct = (product) => {
let productIndex = findProductIndex(product.name)
let productStr = product.name.toLowerCase()
if(productIndex !== -1){
inventory[productIndex].quantity += product.quantity
console.log(`${productStr} quantity updated`)
} else {
inventory.push({name: productStr, quantity: product.quantity})
console.log(`${productStr} added to inventory`)
}
}
console.log(addProduct({name: "FLOUR", quantity: 5}))
const removeProduct = (proName, quantity) => {
let productStr = proName.toLowerCase()
let productIndex = findProductIndex(productStr)
let findName = inventory[productIndex]
console.log(productStr, productIndex, findName)
let proQuantity = findName.quantity
if(productIndex === -1){
console.log(`${productStr} not found`);
}else{
const sub = findName.quantity -= quantity
if(sub >= 1){
console.log(`Remaining ${findName.name} pieces: ${sub}`)
} else if(sub <= 0){
inventory.splice(productIndex, 1)
console.log(`Not enough ${productStr} available, remaining pieces: ${proQuantity}`)
}
}
console.log(inventory)
}
console.log(removeProduct("FlOUR", 2))
// const inventory = [
// {
// name: "chocolate pie",
// quantity: 2
// },
// {
// name: "watermelon",
// quantity: 4
// },
// {
// name: "ladybug",
// quantity: 13
// }
// ]
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0
Challenge Information:
Build an Inventory Management Program - Build an Inventory Management Program