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
- Your code has no type errors
- The console prints
2 addonly accepts text- 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.
Press Run to see the page.
Console
Nothing printed yet.