Build an inventory management program

let inventory=[];

function findProductIndex(pname){

pname=pname.toLowerCase();

let c=0;

for(let i=0;i<inventory.length;i++){

if(inventory\[i\].name==pname){

  c=1;

  return i;

}

}

if(c==0){

return -1;

}

}

function addProduct(obj){

obj.name=obj.name.toLowerCase();

let c=0;

for(let i=0;i<inventory.length;i++){

if(inventory\[i\].name== obj.name){

  inventory\[i\].quantity=inventory\[i\].quantity + obj.quantity;

  console.log(\`${inventory\[i\].name} quantity updated\`);

  c=1;

}

}

if(c==0){

inventory.push(obj);

console.log(obj.name + " added to inventory" );

}

}

function removeProduct(name,qua){

name=name.toLowerCase();

let c=0;

for(let i=0;i<inventory.length;i++){

if(inventory\[i\].name== name){

  c=1;

  if(inventory\[i\].quantity<qua){

    console.log(\`Not enough ${inventory\[i\].name} available, remaining pieces: ${inventory\[i\].quantity}\`);

  }

  else if(inventory\[i\].quantity==qua){

    inventory.splice(i,1);

  }

  else{

    inventory\[i\].quantity=inventory\[i\].quantity - qua;

    console.log(\`Remaining ${inventory\[i\].name} pieces: ${inventory\[i\].quantity}\`)

  }

}

}

if(c==0){

console.log(\`${name} not found\`);

}

}

removeProduct(“FLOUR”, 1)

addProduct({name: “FLOUR”, quantity: 5});

addProduct({name: “FLOUR”, quantity: 5})

removeProduct(“FLOUR”, 5)

removeProduct(“FLOUR”, 5)

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!