diff --git a/classes/Book.js b/classes/Book.js index ee69d54..6e3feb9 100644 --- a/classes/Book.js +++ b/classes/Book.js @@ -1,6 +1,29 @@ // import the Media class: +const Media = require("./Media") -// create your Book class: +class Book extends Media { + constructor(title, year, genre, author, numPages, rating) { + super(title, year, genre); + this.author = author; + this.numPages = numPages; + this.rating = rating; + } + + summary() { + return `Title: ${this.title}, Author: ${this.author}, Year: ${this.year}, Page Count: ${this.numPages}, Genre: ${this.genre}, Rating: ${this.rating}` + } + + static highestRating(arr) { + return arr.sort((a , b) => b.rating - a.rating)[0] + } + + static calculateAverageRating(arr) { + + const arr_ratings = arr.map((book) => book.rating); + return (arr_ratings.reduce((acc, rating) => acc + rating), 0) / arr_ratings.length; + + } +} // don't change below module.exports = Book; diff --git a/classes/Media.js b/classes/Media.js index d4d718b..d65283f 100644 --- a/classes/Media.js +++ b/classes/Media.js @@ -1,4 +1,22 @@ // create your Media class: +const { ALL_MEDIA } = require("./Media"); + +class Media { + static ALL_MEDIA = []; + static totalMediaCount = 0; + constructor(title, year, genre) { + this.title = title; + this.year = year; + this.genre = genre; + ++Media.totalMediaCount; + Media.ALL_MEDIA.push(this); + } + + summary() { + return `Title: ${this.title}, Year: ${this.year}, Genre: ${this.genre}`; + } +} + // uncomment below to export it: module.exports = Media; diff --git a/classes/Movie.js b/classes/Movie.js index 484e7a3..45e580a 100644 --- a/classes/Movie.js +++ b/classes/Movie.js @@ -1,6 +1,25 @@ // import the Media class: - +const Media = require("./Media") // create your Movie class: +class Movie extends Media{ + constructor(title, year, genre, director, duration, rating){ + super(title, year, genre) + this.director = director; + this.rating = rating; + this.duration = duration + + } + summary(){ + return `Title: ${this.title}, Director: ${this.director}, Year: ${this.year}, Genre: ${this.genre}, Rating: ${this.rating}` + } + static longestMovie(arr){ + return arr.reduce((max,current)=> (current.duration > max.duration ? current:max)) + } + + static calculateAverageRating(arr) { + return arr.reduce((acc, movie) => acc + movie.rating, 0) / arr.length; + } +} // don't change below module.exports = Movie; \ No newline at end of file diff --git a/classes/Music.js b/classes/Music.js index b97fe18..90469a5 100644 --- a/classes/Music.js +++ b/classes/Music.js @@ -1,6 +1,30 @@ -// import the Media class: +const Media = require("./Media"); // create your Music class: +class Music extends Media { + constructor(title, year, genre, artist, length) { + super(title, year, genre); + this.artist = artist; + this.length = length; + } + + summary() { + return `Title: ${this.title}, Artist: ${this.artist}, Year: ${this.year}, Genre: ${this.genre}, Length: ${this.length} seconds`; + } + + static shortestAlbum(arr) { + let shortestAlbum = new Music(); + shortestAlbum.length = 10000000; + for (let i = 0; i < arr.length; ++i) { + if (arr[i].length < shortestAlbum.length) shortestAlbum = arr[i]; + } + + return shortestAlbum; + } + +} + + // don't change below module.exports = Music; diff --git a/classes/Podcast.js b/classes/Podcast.js new file mode 100644 index 0000000..f3af6fb --- /dev/null +++ b/classes/Podcast.js @@ -0,0 +1,16 @@ +const Music = require("./Music"); + +class Podcast extends Music{ + constructor(title, year, genre, artist, length, host,epsiodeName, episodeNumber, guests) { + super(title, year, genre, artist, length); + this.host = host; + this.epsiodeName = epsiodeName; + this.episodeNumber = episodeNumber; + this.guests = guests + } + listen(){ + return `${this.title} - Episode: ${this.epsiodeName}. Hosted by ${this.host} and featuring guests ${this.guests}. Length: ${this.length} seconds.` + } +} + +module.exports = Podcast; \ No newline at end of file diff --git a/main.js b/main.js index 102baa9..142bcae 100644 --- a/main.js +++ b/main.js @@ -1 +1,35 @@ -// Import classes here to console.log and debug +const Media = require("./classes/Media"); +const Book = require("./classes/Book"); +const Movie = require("./classes/Movie"); +const Music = require("./classes/Music"); +const Podcast = require("./classes/Podcast"); + +const movie1 = new Movie( + 'Inception', + 2010, + 'Sci-Fi', + 'Christopher Nolan', + 148, + 10 + ) + const movie2 = new Movie( + 'Inception', + 2010, + 'Sci-Fi', + 'Christopher Nolan', + 148, + 10 + ) + const movie3 = new Movie( + 'Inception', + 2010, + 'Sci-Fi', + 'Christopher Nolan', + 148, + 50 + ) + +const music1 = new Music('Lemonade', 2016, 'R&B', 'Beyonce', 3949) +console.log(Media.ALL_MEDIA) + +