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!

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

Julie Maya
Julie Maya
14,666 Points

Push method for movies

I want to add a push function for new movies input on my playlist. I think it's through playlist.js and I tried different ways but it doesn't work out. Please help to advise a way.

playlist.js

function Playlist() {
  this.songs = [];
  this.nowPlayingIndex = 0;
}

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

2 Answers

Sean Walsh
Sean Walsh
8,302 Points

IIRC this is based out of the prototype inheritance section of Object Oriented JavaScript.

If this is the case then you should be able to just pass in one parameter to your add method. For clarity I would change it to media.

Playlist.prototype.add = function(media) {
  this.songs.push(media);
}
Ryan Zimmerman
Ryan Zimmerman
3,854 Points

I would assume what you want to push into your array is an object, having a properties of id, typeof media and link to media.

just a thought