diff --git a/classes/Book.js b/classes/Book.js index ee69d54..b080424 100644 --- a/classes/Book.js +++ b/classes/Book.js @@ -1,6 +1,33 @@ // 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(book) { + let highestRatedBook = book[0] + + for(let i = 0; i < book.length; i++) { + let rating = book[i].rating + + if (rating > highestRatedBook.rating) { + highestRatedBook = book[i] + } + } + + return highestRatedBook + } +} + // don't change below module.exports = Book; diff --git a/classes/Media.js b/classes/Media.js index d4d718b..06da96b 100644 --- a/classes/Media.js +++ b/classes/Media.js @@ -1,4 +1,20 @@ // create your Media class: +class Media { + + constructor(title, year, genre) { + this.title = title + this.year = year + this.genre = genre + Media.totalMediaCount++ + } + + summary() { + return (`Title: ${this.title}, Year: ${this.year}, Genre: ${this.genre}`) + } +} + +Media.totalMediaCount = 0 + // uncomment below to export it: module.exports = Media; diff --git a/classes/Movie.js b/classes/Movie.js index 484e7a3..1abed03 100644 --- a/classes/Movie.js +++ b/classes/Movie.js @@ -1,6 +1,34 @@ // 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.duration = duration + this.rating = rating + } + + summary(){ + return (`Title: ${this.title}, Director: ${this.director}, Year: ${this.year}, Genre: ${this.genre}, Rating: ${this.rating}`) + } + + static longestMovie(movies) { + let longestMovieObject = movies[0] + + for(let i = 0; i < movies.length; i++) { + let duration = movies[i].duration + + if (duration > longestMovieObject.duration) { + longestMovieObject = movies[i] + } + } + + return longestMovieObject + } +} + // 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..70be86a 100644 --- a/classes/Music.js +++ b/classes/Music.js @@ -1,6 +1,34 @@ // 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(albums) { + let shortestAlbumObj = albums[0] + + for(let i = 0; i < albums.length; i++) { + let songLength = albums[i].length + + if (songLength < shortestAlbumObj.length) { + shortestAlbumObj = albums[i] + } + } + + return shortestAlbumObj + } +} + // don't change below module.exports = Music; diff --git a/main.js b/main.js index 102baa9..2a75b57 100644 --- a/main.js +++ b/main.js @@ -1 +1,4 @@ // Import classes here to console.log and debug +const Media = require('./classes/Media') +const Book = require('./classes/Book') +const Movie = require('./classes/Movie') \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 47c194a..55202d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4717,7 +4717,8 @@ "jest-pnp-resolver": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/jest-pnp-resolver/-/jest-pnp-resolver-1.2.3.tgz", - "integrity": "sha512-+3NpwQEnRoIBtx4fyhblQDPgJI0H1IEIkX7ShLUjPGA7TtUTvI1oiKi3SR4oBR0hQhQR80l4WAe5RrXBwWMA8w==" + "integrity": "sha512-+3NpwQEnRoIBtx4fyhblQDPgJI0H1IEIkX7ShLUjPGA7TtUTvI1oiKi3SR4oBR0hQhQR80l4WAe5RrXBwWMA8w==", + "requires": {} }, "jest-regex-util": { "version": "29.4.3",