Skip to content
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
27 changes: 26 additions & 1 deletion classes/Book.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
// import the Media class:

const Media = require('./classes/Media');
// create your Book class:

class Book extends Media{
constructor(title, author, year, genre, 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(bookArray) {
if (bookArray.length === 0) return null;

let highestRatedBook = bookArray[0];
for (let i = 1; i < bookArray.length; i++) {
if (bookArray[i].rating > highestRatedBook.rating) {
highestRatedBook = bookArray[i];
}
}
return highestRatedBook;
}
}

// don't change below
module.exports = Book;
17 changes: 17 additions & 0 deletions classes/Media.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
// create your Media class:
//constructor houses the attributes

class Media{
constructor(title, year, genre,){
this.title = title
this.year = year
this.genre = genre
Media.totalMediaCount++
}

//method always add () then {}
summary(){
return `Title: ${this.title}, Year: ${this.year}, Genre: ${this.genre}`
}
}


Media.totalMediaCount = 0;
// uncomment below to export it:
module.exports = Media;
21 changes: 19 additions & 2 deletions classes/Movie.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
// import the Media class:

const Media = require('./Media')
// create your Movie class:

// don't change below


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}, Duration: ${this.duration}, Rating: ${this.rating}`
}

}


//don't change below
module.exports = Movie;
26 changes: 25 additions & 1 deletion classes/Music.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
// import the Media class:

const Media = require('./classes/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}`
}
static shortestAlbum(musicArray){
if(musicArray.length ===0)
return null;

let shortestSong = musicArray[0]
for (let i = 1; i <musicArray.length; i++) {
shortestSong = musicArray[i]
}
return shortestSong
}


}

// don't change below
module.exports = Music;
28 changes: 28 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const Media = require('./classes/Media');
const Book = require('./classes/Book');
const Movie = require('./classes/Movie');



//media examples
const book = new Media('The Catcher in the Rye', 1951, 'Fiction');
Media.totalMediaCount; // 1
const music = new Media('Abbey Road', 1969, 'Rock');
Media.totalMediaCount; // 2
music.summary(); // "Title: Abbey Road, Year: 1969, Genre: Rock"


//book examples
const book1 = new Book('To Kill a Mockingbird', 1960, 'Fiction', 'Harper Lee', 281, 4.4);
Media.totalMediaCount; // 1
const book2 = new Book('The Bluest Eye', 1970, 'Fiction', 'Toni Morrison', 206, 4.6);
Media.totalMediaCount; // 2
book1.summary(); // "Title: To Kill a Mockingbird, Author: Harper Lee, Year: 1960, Page Count: 281, Genre: Fiction, Rating: 4.4"
Book.highestRating([book1, book2]); // Returns book2

//movie examples
const movie1 = new Movie('Inception', 2010, 'Sci-Fi', 'Christopher Nolan', 148, 4.5);
const movie2 = new Movie('The Godfather', 1972, 'Crime', 'Francis Ford Coppola', 175, 4.7);
Media.totalMediaCount; // 2
movie1.summary(); // "Title: Inception, Director: Christopher Nolan, Year: 2010, Genre: Sci-Fi, Rating: 4.5"
Movie.longestMovie([movie1, movie2]); // Returns movie2
Loading