Command Palette

Search for a command to run...

Hectal
Phase 6: Objects
JavaScript · Exercise 4 of 5 PreviousNext
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

  1. countVotes counts each choice
  2. countVotes([]) returns an empty object
  3. topChoice returns the key with the most votes
  4. The page lists every choice with its count
  5. The page shows tea as 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.