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

Live Character Counter

easy0%0 of 1 solved

Problem statement

A message field that tells the user how much room is left. The counter reacts as the user types, deletes, or pastes, warns them as they near the limit, and stops the field from ever going over it.

Demo

The page, styles, textarea, and counter element are already scaffolded and wired. Only the initializeCharacterCounter function is missing — implement it in src/js/characterCounter.ts so every test passes. Do not edit any other file.

What to implement

  • React to the user changing the field as they change it, rather than to individual key presses.
  • Show how many characters have been used out of the maximum you were given, both before anything is typed and after every change.
  • Mark the counter with a warning label once 20 or fewer characters are left, and take that label off again once more than 20 are left.
  • Never let the field hold more characters than the maximum, whether the text was typed or pasted in.
  • Keep deleting working at all times, including once the field is already full.
  • Use the maximum you were given — nothing should be hardcoded.
  • Change only the field and the counter you were given, and do not add or remove any elements on the page.

More in Events & Event Handling

See the module
Quantity StepperWire increment / decrement buttons to a numeric display bound between 1 and a supplied maximum, disabling each button at its bound. Values typed directly into the field are clamped on blur, and a change callback fires only when the value actually changes — not on repeat writes of the same number.0%0 of 1 solvedeasyDismissible 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 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.