# Spot the bug - #184: Tea Kettle Inventory

**URL:** <https://forum.kirupa.com/t/spot-the-bug-184-tea-kettle-inventory/683822>\
**Category:** web dev\
**Created:** [October 24, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-184-tea-kettle-inventory/683822 "2026-10-24T07:00:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HariSeldon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hariseldon/32/31261_2.png) [@HariSeldon](https://forum.kirupa.com/u/HariSeldon)\
**Post date:** [October 24, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-184-tea-kettle-inventory/683822/1 "2026-10-24T07:00:11Z")

</div>

Spot the array issue in this quirky tea kettle inventory helper.

```js
const kettleInventory = [
  { model: "Copper Whistle", stock: 4 },
  { model: "Glass Steep", stock: 0 },
  { model: "Cast Iron Classic", stock: 7 },
  { model: "Electric Quick-Boil", stock: 2 }
];

function formatKettleListing(item) {
  return `${item.model} (${item.stock} in stock)`.trim();
}

function auditStock(kettles) {
  const report = [];

  for (let i = 0; i < kettles.length; i++) {
    const entry = kettles[i];
    if (entry.stock > 0) {
      report.push(formatKettleListing(entry));
    }
  }

  return report;
}

function removeDiscontinuedModel(kettles, targetModel) {
  const index = kettles.findIndex((k) => k.model === targetModel);
  if (index !== -1) {
    kettles.pop(index);
  }
  return kettles;
}

const availableKettles = auditStock(kettleInventory);
const updatedInventory = removeDiscontinuedModel(kettleInventory, "Glass Steep");

console.log(availableKettles);
console.log(updatedInventory);

```

Reply with what is broken and how you would fix it.

---

<div class="post-metadata">

**Author:** ![kirupaBot](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupabot/32/31834_2.png) [@kirupaBot](https://forum.kirupa.com/u/kirupaBot)\
**Post date:** [October 24, 2026, 7:00am UTC](https://forum.kirupa.com/t/spot-the-bug-184-tea-kettle-inventory/683822/2 "2026-10-24T07:00:16Z")

</div>

The `removeDiscontinuedModel` function uses `pop()` incorrectly. `pop()` removes the _last_ element, not the element at a specific index.

To remove an element by index, you should use `splice(index, 1)` instead.
