← Back to Stage 5
Stage 5#502Coding · Senior~10 min read

Implement an accessible money input contract

Design System, UX, Security · Domain Components

Define parsing, formatting, validation, keyboard behavior, aria-describedby errors, and minor-unit output.

Prompt

Implement an accessible money input contract

This is a hands-on rep. Attempt the drill before reading the model answer, then narrate the tradeoffs as if an interviewer is watching.

💡
Tip

This is a compact but high-signal coding exercise.

Foundation

What to ground before answering

Define parsing, formatting, validation, keyboard behavior, aria-describedby errors, and minor-unit output.

Focus vocabulary: forms, a11y, money.

The useful mental model is not to memorize a perfect answer. It is to explain what owns the data, what can fail, what the user sees, and what test would prove the behavior.

Coding drill

Implement accessible money input parsing

Target: 20mNot run

Make the behavior executable before comparing against the model answer.

type MoneyInputState =
  | { ok: true; minor: string; ariaInvalid: false }
  | { ok: false; error: string; ariaInvalid: true };

function moneyInputState(value: string, decimals: number): MoneyInputState {
  // TODO: parse safely and expose aria-invalid state.
  return { ok: false, error: 'not implemented', ariaInvalid: true };
}
TypeScript · runnable
System design

Interview explanation prompt

  • What problem is this practice item really testing?
  • What state or contract boundary must be explicit?
  • What edge case would cause a production regression?
  • What would you test first?
  • How would you explain the tradeoff in two minutes?
Self-grade

Self-grade

  • Strong answer handles the edge cases before polishing syntax.
  • Strong answer explains why the chosen type or function boundary prevents bugs.
  • Weak answer passes only the happy path or hides uncertainty in booleans and nullable fields.

Model Answer

function moneyInputState(value: string, decimals: number): MoneyInputState {
  const trimmed = value.trim();
  if (trimmed === '') return { ok: false, error: 'Amount is required', ariaInvalid: true };
  if (!/^\\d+(?:\\.\\d+)?$/.test(trimmed)) return { ok: false, error: 'Use numbers only', ariaInvalid: true };
  const [whole, fraction = ''] = trimmed.split('.');
  if (fraction.length > decimals) return { ok: false, error: 'Too many decimal places', ariaInvalid: true };
  return { ok: true, minor: whole + fraction.padEnd(decimals, '0'), ariaInvalid: false };
}
Review

Recall before moving on

  • What is the one-sentence answer for "Implement an accessible money input contract"?
  • Which real experience from PR TIMES, React/TypeScript migration, or systems work supports it?
  • What edge case would you volunteer before the interviewer asks?
  • What is the smallest test or artifact that proves the design works?