Command Palette

Search for a command to run...

Hectal
Phase 14: Advanced Language
JavaScript · Exercise 1 of 5Next
Intermediate

Make a playlist iterable

The playlist object holds its songs in a songs array. Make the object itself iterable, so [...playlist] and for (const song of playlist) give the songs in order.

Then fill the #songs list with one <li> per song, using a for...of loop over playlist (not over playlist.songs).

It must work more than once: spreading playlist twice gives the four songs both times.

What Check tests

  1. playlist has a [Symbol.iterator] method
  2. Spreading playlist gives the four songs in order
  3. It works twice in a row
  4. The page lists the four songs
  5. The loop is for...of over playlist itself
  6. No errors

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.