Command Palette

Search for a command to run...

Hectal
Phase 6: Classes and Object-Oriented TypeScript
TypeScript · Exercise 1 of 6Next
Beginner

Build a Playlist Class

The class Playlist declares two fields but never sets them, so strict mode complains, and the code at the bottom calls methods that do not exist yet.

Give Playlist a constructor that sets name from its argument, start songs as an empty list, and add the methods add(song: string) and count(). The program should print 2.

What Check tests

  1. Your code has no type errors
  2. The console prints 2
  3. add only accepts text
  4. A playlist needs a name

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.

Console

Nothing printed yet.