Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const library = function(name, creator) {
- this.name = name;
- this.creator = creator;
- this.tracks = [];
- this.playlists = [];
- this.addTrack = track => this.tracks.push(track);
- this.addPlaylist = playlist => this.playlists.push(playlist);
- };
- const playlist = function(name) {
- this.name = name;
- this.tracks = [];
- this.addTrack = track => this.tracks.push(track);
- this.plRating = 0;
- this.rating = () => {
- let ratesum = 0;
- for (song in this.tracks) {
- ratesum = ratesum += this.tracks[song].Rating;
- }
- let orating = ratesum / this.tracks.length;
- return orating;
- };
- this.duration = () => {
- let dursum = 0;
- for (song in this.tracks) {
- dursum = dursum += this.tracks[song].length;
- }
- return dursum;
- };
- };
- const track = function(name, rating, length) {
- this.name = name;
- this.Rating = rating;
- this.length = length;
- };
- const myLib = new library();
- const Dog_Police = new track('Dog Police', 5, 3.1);
- const Love_Shack = new track('Love Shack', 10, 3.1);
- const Sandstorm = new track('Sandstorm by Darude', 3, 5.3);
- const myPL = new playlist('Cool Songs');
- myPL.addTrack(Dog_Police);
- myPL.addTrack(Love_Shack);
- myPL.addTrack(Sandstorm);
- console.log(myPL.duration());
Add Comment
Please, Sign In to add comment