Inventory tracker · Edition 2

Application logic

Implement and test an item counter.

Before you begin

Read an input, change a value, and render an output after a click.

The practical problem

Build an inventory counter for a fictional repair club. The counter starts at eight units. Stock movements are allowed only as positive whole numbers.

Build it step by step

  1. Write the rules for a valid receipt, a valid issue, and a rejected issue before writing code.
  2. Use one numerical variable as the source of truth. Calculate the next count before updating it.
  3. Show both the current count and the outcome of the last action. Test your rules in the interactive preview.

Acceptance criteria

  • Starting stock is 8; adding 3 produces 11; removing 11 produces 0.
  • Removing 1 from 0 leaves the count at 0 and explains why.
  • Zero, negative or fractional movement is rejected without changing stock.

Common mistake

Avoid keeping a separate variable and a separately edited display. Render from the same confirmed count after each action.

How to assess your work

Run the checks below and write down what you expected, what happened, and one change you can demonstrate. Self-checks are practice evidence, not a verified grade.

Build

Choose an initial count and write one function to add items and one to subtract them. Keep quantities non-negative.

Test

Run the exported JavaScript locally. Test zero, a normal addition, and subtracting too many items.

Reflect

Which rule did you enforce in code, and which rule did you explain in the interface?

Starter project and AI hint

Show a count, an Add action, and a Remove action. Decide what happens at zero.

Ask for an explanation of state and one test of its boundary.