StaffCoder
TypeScript
Vanilla TypeScriptTypeScript 7.0
6 modules · 24 challengesSign up
Module 2 · Events & Event Handling

Quantity Stepper

easy0%0 of 1 solved

Problem statement

A cart quantity control built with Vanilla TypeScript and standard DOM APIs. The page provides the finished stepper markup — a decrement button, a numeric input, and an increment button — but none of the controls do anything, so a shopper can order a negative amount or more than the available stock.

Demo

The page, styles, and stepper markup are already scaffolded and wired. Only the initializeQuantityStepper function is missing — implement it in src/js/quantityStepper.ts so every test passes. Do not edit any other file.

What to implement

  • Make the increment button raise the quantity by one, and the decrement button lower it by one.
  • Keep the quantity between one and the maximum you are given, no matter how the user interacts with the control.
  • Keep the input showing the current quantity at all times.
  • Turn off the decrement button once the quantity reaches the lowest allowed value, and the increment button once it reaches the maximum.
  • Turn a button back on as soon as the quantity moves away from that limit.
  • Pull a quantity typed straight into the field back into the allowed range once the user clicks away.
  • Report the new quantity through the callback you were given every time the quantity changes.
  • Stay silent when an interaction leaves the quantity exactly as it was.
  • The limit must come from the maximum you were given — nothing should be hardcoded.
  • Work with the controls already on the page, without replacing them or touching anything else in the document.

More in Events & Event Handling

See the module
Dismissible DialogOpen and close a dialog element, closing on the close button, on Escape, and on a click of the backdrop but not the panel. Focus moves into the dialog on open and returns to the element that opened it on close, and the key listener is removed on close so a later Escape press does nothing.0%0 of 1 solvedeasyLive Character CounterUpdate a counter on every input event showing characters used against a maximum, add a warning class within the last 20 chars, and block further input beyond the limit while still allowing deletion. Pasting an over-length string truncates to the limit. Use the input event, not keydown.0%0 of 1 solvedeasyFilter ToolbarWire a text input, a category select, and an in-stock checkbox so that changing any of them filters an in-memory array and re-renders the list under AND semantics — two active filters compose, not replace each other. Show a result count and a no-matches message; clearing a filter restores the previous set; the original array is never mutated.0%0 of 1 solvedeasy

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.