Question presented to candidate: "Build a temperature converter with two boxes, Celsius and Fahrenheit. Typing in either box should update the other one live. Think about what happens while someone is halfway through typing a number, and about ugly floating point results."
Requirements:
- Two labelled inputs, °C and °F; editing one updates the other as you type.
- The box being typed in keeps exactly what the user typed (for example "37." or "-").
- Results rounded to at most two decimals, without trailing zeros or "-0".
- Empty or half-typed input ("", "-", ".") clears the other box without an error; clearly invalid input ("abc") shows an error tied to the input.
- A note when the temperature is below absolute zero (-273.15 °C).
What a strong answer should cover:
- One source of truth: store which box was edited and its raw text; derive the other box. Two independent states that update each other lead to loops or rounding drift.
- The formulas
F = C × 9/5 + 32andC = (F − 32) × 5/9, and floating point output such as36.6 → 97.88000000000001. - Why a text input with
inputmode="decimal"beatstype="number"here (half-typed values like "-" read as an empty string). - Validation states with
aria-invalidandaria-describedby, and a status message. - Keeping conversion and formatting in a pure helper module that is easy to test.
Clarifying questions expected:
- "How many decimals should results show?"
- "Should Kelvin be included?"
- "Do we show an error while the user is mid-way through typing a negative number?"
Code / implementation expected: Yes. A component plus a small pure conversion helper, roughly 50-80 lines.