Guest User

Untitled

a guest
Feb 17th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. const library = function(name, creator) {
  2. this.name = name;
  3. this.creator = creator;
  4. this.tracks = [];
  5. this.playlists = [];
  6. this.addTrack = track => this.tracks.push(track);
  7. this.addPlaylist = playlist => this.playlists.push(playlist);
  8. };
  9.  
  10. const playlist = function(name) {
  11. this.name = name;
  12. this.tracks = [];
  13. this.addTrack = track => this.tracks.push(track);
  14. this.plRating = 0;
  15. this.rating = () => {
  16. let ratesum = 0;
  17. for (song in this.tracks) {
  18. ratesum = ratesum += this.tracks[song].Rating;
  19. }
  20. let orating = ratesum / this.tracks.length;
  21. return orating;
  22. };
  23. this.duration = () => {
  24. let dursum = 0;
  25. for (song in this.tracks) {
  26. dursum = dursum += this.tracks[song].length;
  27. }
  28. return dursum;
  29. };
  30. };
  31.  
  32. const track = function(name, rating, length) {
  33. this.name = name;
  34. this.Rating = rating;
  35. this.length = length;
  36. };
  37.  
  38. const myLib = new library();
  39. const Dog_Police = new track('Dog Police', 5, 3.1);
  40. const Love_Shack = new track('Love Shack', 10, 3.1);
  41. const Sandstorm = new track('Sandstorm by Darude', 3, 5.3);
  42.  
  43. const myPL = new playlist('Cool Songs');
  44.  
  45. myPL.addTrack(Dog_Police);
  46. myPL.addTrack(Love_Shack);
  47. myPL.addTrack(Sandstorm);
  48.  
  49. console.log(myPL.duration());
Add Comment
Please, Sign In to add comment