Skip to content

add task solution #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion classes/Book.js
Original file line number Diff line number Diff line change
@@ -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;
}

static highestRating(books) {
let highest = books[0];

for (let i = 1; i < books.length; i++) {
if (books[i].rating > highest.rating) {
highest = books[i];
}
}

return highest;
}

summary() {
return `Title: ${this.title}, Author: ${this.author}, Year: ${this.year}, Page Count: ${this.numPages}, Genre: ${this.genre}, Rating: ${this.rating}`;
}
}
// don't change below
module.exports = Book;
15 changes: 15 additions & 0 deletions classes/Media.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
// create your Media class:
class Media {
static totalMediaCount = 0;

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}`;
}
}

// uncomment below to export it:
module.exports = Media;
25 changes: 24 additions & 1 deletion classes/Movie.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
// 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;
}

static longestMovie(movies) {
let longest = movies[0];

for (let i = 1; i < movies.length; i++) {
if (movies[i].rating > longest.rating) {
longest = movies[i];
}
}

return longest;
}

summary() {
return `Title: ${this.title}, Director: ${this.director}, Year: ${this.year}, Genre: ${this.genre}, Rating: ${this.rating}`;
}
}
// don't change below
module.exports = Movie;
24 changes: 23 additions & 1 deletion classes/Music.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
// 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;
}

static shortestAlbum(musics) {
let shortest = musics[0];

for (let i = 1; i < musics.length; i++) {
if (musics[i].length < shortest.length) {
shortest = musics[i];
}
}

return shortest;
}

summary() {
return `Title: ${this.title}, Artist: ${this.artist}, Year: ${this.year}, Genre: ${this.genre}, Length: ${this.length} seconds`;
}
}
// don't change below
module.exports = Music;
9 changes: 9 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
// 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');

console.log(Media);
console.log(Book);
console.log(Movie);
console.log(Music);
Loading