Home
← All questions

Poll widget | Frontend Machine Coding

EasyPremiumMachine Coding

Frontend Machine Coding interview practice: Build a poll/voting widget that shows results as percentages after voting.

Problem

Build a poll widget where a user votes for one option and sees the live result distribution.

Requirements

  • Render a question and multiple options.
  • Selecting an option records the vote and shows each option's percentage and a bar.
  • Prevent double voting (lock after a vote) or allow changing the vote (your choice — state it).
  • (Bonus) Show total votes; animate the result bars.

Hints / Approach

  • State: options: [{ id, label, votes }] and votedOptionId.
  • Percentage = option.votes / totalVotes * 100; render a bar with width: ${pct}%.
  • For changing votes, decrement the previous option and increment the new one.
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium