Build a Sukuma Price Calculator

The same vegetable, two units. Build a calculator that switches between Per kg and Bunch pricing and recomputes the total whenever the user changes anything.

Step 1 of 3

Two units of measure, one item

At any market, sukuma is sold two ways:

  • Per kg — KSh 60 per kilogram. The customer specifies weight.
  • Per bunch — KSh 30 per pre-tied bunch. The customer specifies count.

The interface is the same shape both times: a quantity input and a total. Only the price-per-unit and the unit label change. This is a perfect place to practice an if branch, object lookup, and event-driven recalculation.

Think of it this way: It is the same vegetable in two different packaging units — like buying maize as flour (per kg) versus a single cob (per piece). The price logic is identical; the multiplier differs.
Tip

Form input values are always strings, even when the input type is number. Convert with Number(value) or parseFloat(value) before doing maths, or you will end up concatenating strings instead of adding.