Intermediate
Count the votes
Write countVotes(votes): given an array of strings, return an object with one key per choice and the number of votes as its value.
Write topChoice(counts): given such an object, return the key with the most votes.
Use them on the votes array: show one <li> per choice in #results (like tea: 3) and put the winner's name in #winner.
What Check tests
countVotescounts each choicecountVotes([])returns an empty objecttopChoicereturns the key with the most votes- The page lists every choice with its count
- The page shows
teaas the winner
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Your page
Press Run to see the page.
Console
Nothing logged yet.