Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Object-Oriented JavaScript (2015) Constructor Functions and Prototypes Making the UI Work

Playlist items don't show, Uncaught TypeError this.songs[i].toHTML is not a function

I'm pretty sure I've gone through the code with a fine-tooth comb to make this look just like Andrew's, but the console gives me the error in the subject line. Note that my code reads list.innerHTML += this.songs[i].toHTML();, with parentheses that the error message doesn't pick up (this might be normal, I'm not sure).

Here is a link to my workspace (forked): https://w.trhou.se/an17ecy1z8

It's likely I missed something very small–I hope someone with sharper eyes can pick it out.

Thanks!

4 Answers

Hey there,

The problem is with the add function in playlist.js.

playlist.js
Playlist.prototype.add = function() {
  this.songs.push(Song);
};

The add function does not have a song parameter defined, and you're trying to push a copy of the Song constructor into the songs array. Here's the fix:

playlist.js
Playlist.prototype.add = function(song) {
  this.songs.push(song);
};

Cheers!

David Elston
David Elston
8,112 Points

Had the same problem and went looking for some help, thanks!

Erwin Meesters
Erwin Meesters
15,088 Points

Your playlist.js contains the error. The Playlist.prototype.add function needs a little tweak:

Playlist.prototype.add = function(song) {
  this.songs.push(song);
};

That was it. Thanks so much!

Tom Emody
Tom Emody
1,808 Points

Thank you, even if this is old.... I had the exact same issue!