Build an Inventory Management Program - Build an Inventory Management Program

Tell us what’s happening:

its corecct but not working please clear it and send
check and say the erorrs

Your code so far

var inventory = ;

function findProductIndex(productName) {
var name = productName.toLowerCase();
for (var i = 0; i < inventory.length; i++) {
if (inventory[i].name === name) {
return i;
}
}
return -1;
}

function addProduct(product) {
var name = product.name.toLowerCase();
var index = findProductIndex(name);

if (index !== -1) {
inventory[index].quantity += product.quantity;
console.log(name + " quantity updated");
} else {
inventory.push({ name: name, quantity: product.quantity });
console.log(name + " added to inventory");
}
}

function removeProduct(productName, quantity) {
var name = productName.toLowerCase();
var index = findProductIndex(name);

if (index === -1) {
console.log(name + " not found");
return;
}

var product = inventory[index];

if (product.quantity < quantity) {
console.log("Not enough " + name + " available, remaining pieces: " + product.quantity);
} else if (product.quantity === quantity) {
inventory.splice(index, 1);
} else {
product.quantity -= quantity;
console.log("Remaining " + name + " pieces: " + product.quantity);
}
}

var inventory = [];

function findProductIndex(productName) {
  var name = productName.toLowerCase();
  for (var i = 0; i < inventory.length; i++) {
    if (inventory[i].name === name) {
      return i;
    }
  }
  return -1;
}

function addProduct(product) {
  var name = product.name.toLowerCase();
  var index = findProductIndex(name);

  if (index !== -1) {
    inventory[index].quantity += product.quantity;
    console.log(name + " quantity updated");
  } else {
    inventory.push({ name: name, quantity: product.quantity });
    console.log(name + " added to inventory");
  }
}

function removeProduct(productName, quantity) {
  var name = productName.toLowerCase();
  var index = findProductIndex(name);

  if (index === -1) {
    console.log(name + " not found");
    return;
  }

  var product = inventory[index];

  if (product.quantity < quantity) {
    console.log("Not enough " + name + " available, remaining pieces: " + product.quantity);
  } else if (product.quantity === quantity) {
    inventory.splice(index, 1);
  } else {
    product.quantity -= quantity;
    console.log("Remaining " + name + " pieces: " + product.quantity);
  }
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36

Challenge Information:

Build an Inventory Management Program - Build an Inventory Management Program

what is not working?

Note - I would not use var and I don’t think the course encourages it at all

In this video/transcript that talks about using let or const to declare variables, it says:

You can also use the var keyword, but it’s not as recommended anymore. The var is kind of like let , except it has a wider scope, which is more likely to cause problems in your program.