Question presented to candidate: "Build a small poll widget: a question, four options and a Vote button. After voting, the user sees each option's share as a bar with a percentage and a count, their own choice highlighted, and the total. A user must not be able to vote twice."
Requirements:
- Options start with existing vote counts; the user picks one option, then submits.
- The Vote button is disabled until something is selected.
- After voting: results view with a bar, percentage and count per option, "your vote" marker and the total. Bars animate their width with CSS.
- One vote only: the voting controls disappear, and the vote function itself refuses a second vote (even two clicks in the same tick).
- Percentages are whole numbers that add up to exactly 100.
What a strong answer should cover:
- Separating state (counts, chosen option, voted option) from derived values (total, percentages), which are computed, never stored.
- Updating counts immutably and guarding the vote with the latest state, not a stale value.
- Why
Math.roundcan give 99 or 101 and how the largest remainder method fixes it. - Native radio inputs in a
fieldsetwith alegendfor free keyboard support and screen-reader grouping. - Results announced politely and bars marked decorative because the text already says the number.
Clarifying questions expected:
- "Should results be visible before voting, or only after?"
- "Can a user change their vote, or is it final?"
- "Does the vote need to survive a reload or be saved to a server in this version?"
Code / implementation expected: Yes. A working widget with the single-vote rule and correct percentages.