Tell us what’s happening:
I just fucking hate javascript at this point(can’t solve steps 8-16 excluding 11)
Your code so far
let inventory = [
]
function findProductIndex(name) {
for (let i = 0; i < inventory.length; i++) {
if (inventory[i].name.toLowerCase() === name.toLowerCase()) {
return i
}
}
return -1
}
function addProduct(obj) {
if (findProductIndex(obj.name) > -1) {
inventory[findProductIndex(obj.name)].quantity += obj.quantity
return `${obj.name.toLowerCase()} quantity updated`
} else {
inventory.push(obj)
return `${obj.name.toLowerCase()} quantity updated`
}
}
function removeProduct(name, quantity) {
if (findProductIndex(name) === 1) {
return `${name} not found`
} else {
const remainingQuantity = inventory[index].quantity - quantity
const daFuckingProduct = findProductIndex(name)
if (remainingQuantity > 0) {
inventory[daFuckingProduct].quantity = remainingQuantity
return `Remaining ${name} pieces: ${remainingQuantity}`
} else if (remainingQuantity == 0) {
inventory.splice(objectIndex, 1)
} else if (remainingQuantity < 0) {
return `Not enough ${name} available, remaining pieces: ${remainingQuantity}`
}
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 OPR/123.0.0.0
Challenge Information:
Build an Inventory Management Program - Build an Inventory Management Program