let inventory = [x];
function findProductIndex(productName) {
for(let i=0; i<inventory.length; i++) {
if(inventory[i].name === productName.toLowerCase()) {
return i;
}
}
return -1;
}
const addProduct = productObject => {
let productIndex = findProductIndex(productObject.name.toLowerCase());
if(productIndex === -1) {
inventory.push(productObject);
console.log(productObject.name + " " + "added to inventory");
}
else {
inventory[productIndex].quantity += productObject.quantity;
console.log(productObject.name + " " + "quantity updated");
}
}
1 Like
Please Tell us what’s happening in your own words.
Learning to describe problems is hard, but it is an important part of learning how to code.
Also, the more you say, the more we can help!
1 Like
what project are you doing? what are you stuck on? we can’t help without some infos
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.
The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.
Thank you.