Tally a Poll
Write the code, see it run, pass the checks.
The problem
- easy
- Code
The Poll component gets an options prop, a list of answers (the preview uses "Tea", "Coffee" and "Juice"). For each option, show a button labelled "Vote Tea" (and so on) and a line reading like "Tea: 2 votes (40%)": the option's votes, with "vote" for exactly 1, and its share of all the votes as a percentage rounded to the nearest whole number. Before anyone votes, each line reads like "Tea: 0 votes (0%)". Below them, show "Total: 5 votes" (again "vote" for exactly 1). Keep only the counts in state, and work out the percentages and the total while rendering.
Your code must pass
- Starts with no votes
- One vote is 100% of the total
- Shares are rounded to whole percentages
- Works for any options passed in