Build an Inventory Management Program - Build an Inventory Management Program

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

A Few Things to Fix

  1. Incorrect condition check: You’re checking “if (findProductIndex(name) === 1)”, but that only matches if the item is at index 1. What you really want is to check if the item doesn’t exist, so it should be “=== -1”.

  2. Missing variable declarations: You’re using “index” and “objectIndex” without declaring them. Since you’re already calling “findProductIndex(name)”, just store that result in a variable and reuse it.

  3. Order of operations: You’re calculating “remainingQuantity” before you even find the index of the product. Flip that—get the index first, then do the math.

What are tests 8-16?

Where did you get stuck trying to fix the failing tests?

It’s recommended to guide the learners to fixing the problems in their code themselves instead of giving them the solution in words.

Man what do you think I’ve been doing for the last 2 days

I’m not sure what you mean.

Can you try to answer these two questions:

What are tests 8-16?

Where did you get stuck trying to fix the failing tests?

That’s exactly what I have been tryna do

you are trying to answer those two questions for the last two days? if you tell us where you are stuck we can try to help

It should not take 2 days to answer those two questions?

Thanks man! And thank you for your time!

You’re dealing with an incredibly slow guy here(I have no idea how to troubleshoot)

No troubleshooting required to write out what tests 8-16 are and what you have tried so far. You just need to type out answers

Oh I solved it now. Thanks for your time!

1 Like