Question presented to candidate: "Build a small flight booker. The user picks one-way or return, types a departure date and, for a return trip, a return date. Invalid dates should be flagged, the return date only matters for return trips and can never be before departure, and Book should only work when everything is valid. On booking, show a confirmation message."
Requirements:
- A select with "One-way flight" and "Return flight"; two text inputs in
YYYY-MM-DDformat, both starting on the same date. - The return input is disabled for one-way trips, and its value is kept if the user switches back.
- Each input shows its own error: empty, wrong format, or a date that does not exist (for example
2026-02-30). - For return trips, the return date must be on or after the departure date; show the trip length in nights when valid.
- Book is disabled while anything is invalid; booking shows "You have booked a one-way flight on ..." or "... a return flight departing ... and returning ...". Editing anything clears the old confirmation.
What a strong answer should cover:
- Minimal state (trip type, two strings, the confirmation) with everything else derived: errors, whether Book is enabled, nights.
- Strict date parsing: why
new Date("2026-02-30")is not a validator (it rolls over), and why parsing date-only strings can shift a day across time zones. - Cross-field validation (return vs departure) that only runs when both fields are individually valid.
- Constraints between widgets: disabling the return input, keeping its value, and ignoring its errors for one-way trips.
- Accessibility: labels,
aria-invalid,aria-describedby, and arole="status"confirmation.
Clarifying questions expected:
- "Should I use a native date picker or text inputs with a fixed format?"
- "Is a departure date in the past allowed, and whose time zone defines today?"
- "Is a same-day return allowed?"
Code / implementation expected: Yes. The booker component with a strict date parser, derived validation and enable rules, and a confirmation message.