StaffCoder
TypeScript
Vanilla TypeScriptTypeScript 7.0
6 modules · 24 challengesSign up
Module 6 · Arrays & Data Transformation

Order Totals

easy—No data yet

Problem statement

An order summary panel whose figures are computed from an in-memory array of order lines. A computation and a DOM rendering must together produce the item count, subtotal, discount, tax, and grand total for the order, using Vanilla TypeScript and standard DOM APIs.

Demo

The page, styles, mock data, and summary panel markup are already scaffolded and wired. Only the computeSummary function in src/js/totals.ts and the renderSummary function in src/js/render.ts are missing — implement them so every test passes. Do not edit any other file.

What to implement

  • Show the total number of items in the order.
  • Show the subtotal of every line that counts toward the order.
  • Show the total discount deducted from the order.
  • Show the tax that applies to the discounted subtotal.
  • Show the grand total that ties out to the invoice.
  • Keep cancelled lines and zero-quantity lines out of every figure.
  • Show 0 for the item count and 0.00 for every money figure when the order is empty or fully cancelled — never NaN.
  • Write the item count as a whole number and every money figure with two decimals.
  • Leave the order lines you were given unchanged, and leave the panel and the rest of the page as you found them.
  • Everything shown must come from the order lines you were given — nothing should be hardcoded.

More in Arrays & Data Transformation

See the module
Group Bookings By DayReduce a bookings array into a map keyed by date, each entry holding its bookings sorted by start time and a count. Every day in the requested range is included — days with no bookings appear with an empty list — keys are returned in chronological order, and a booking outside the range is excluded.—No data yeteasyLeaderboard SortingSort leaderboard entries by score descending with a documented tiebreak (earlier finish time, then name) without mutating the input. Support an ascending toggle and return a position for each entry, sharing a position number across genuine ties. The order is stable across repeated calls.—No data yeteasyInventory Summary PanelTransform a stock array into a summary (total value, low-stock count, out-of-stock list, top categories by value) and render each part into the panel. Values render formatted, every derived figure comes from the transform rather than the DOM, and re-running with new data replaces the rendered summary rather than appending.—No data yeteasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.