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
warninglabel 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.
