Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Parent Class */
- class Media {
- constructor(title) {
- this._title = title;
- this._isCheckedOut = false;
- this._ratings = [];
- }
- get title() {
- return this._title;
- }
- get isCheckedOut() {
- return this._isCheckOut;
- }
- get ratings() {
- return this._ratings;
- }
- set isCheckedOut(checkedOut) {
- this._isCheckOut = checkedOut;
- }
- toggleCheckedOutStatus() {
- this._isCheckedOut = !this._isCheckedOut;
- }
- getAverageRating() {
- let ratingsSum = this._ratings.reduce((currentSum, rating) => currentSum + rating, 0);
- let ratingsLength = this._ratings.length;
- let average = ratingsSum/ratingsLength;
- this._ratings = average;
- return this._ratings;
- }
- addRating(ratings) {
- if(ratings < 1 || ratings > 5 ) {
- console.log('Error! Please rate between 1 and 5')
- } else {
- this._ratings.push(ratings);
- }
- }
- }
- class Book extends Media{
- constructor(author, title, pages) {
- super(title);
- this._author = author;
- this._pages = pages;
- }
- get author() {
- return this._author;
- }
- get pages() {
- return this._pages;
- }
- }
- class Movie extends Media {
- constructor(director, title, runTime, movieCast) {
- super(title);
- this._director = director;
- this._runTime = runTime;
- this._movieCast = movieCast;
- }
- get director() {
- return this._director;
- }
- get runTime() {
- return this._runTime;
- }
- }
- class Cd extends Media {
- constructor(title, artist, songs) {
- super(title);
- this._artist = artist;
- this._songs = [];
- }
- get artist() {
- return this._artist;
- }
- get songs() {
- return this._songs;
- }
- addSong(songs) {
- this._songs.push(songs);
- }
- shuffle(songs) {
- for (var i = songs.length - 1; i > 0; i--) {
- var j = Math.floor(Math.random() * (i + 1));
- var temp = songs[i];
- songs[i] = songs[j];
- songs[j] = temp;
- }
- return songs;
- }
- }
- class Catalog {
- constructor(mediaList){
- this._MyCatalog = [mediaList];
- }
- get mediaList() {
- return this._mediaList;
- }
- set mediaList(newMedialist) {
- this._MyCatalog.push(newMedialist);
- }
- }
- const historyOfEverything = new Book('Bill Bryson', 'A Short History of Nearly Everything', 544);
- //console.log(historyOfEverything);
- historyOfEverything.toggleCheckedOutStatus();
- //console.log(historyOfEverything._isCheckedOut);
- historyOfEverything.addRating(4);
- historyOfEverything.addRating(5);
- historyOfEverything.addRating(5);
- //console.log(historyOfEverything.getAverageRating());
- const tgg = new Book('F. Scott Fitzgerald', 'The Great Gatsby', 192);
- const avengers = new Movie('Joss Whedon', 'Avengers', 143);
- //Console logs for the movie
- //console.log(avengers);
- avengers.toggleCheckedOutStatus();
- console.log(avengers._isCheckedOut);
- avengers.addRating(4);
- avengers.addRating(4);
- avengers.addRating(5);
- console.log(avengers.getAverageRating());
- // Outputs to console if the book is checked out in a fancy way
- if (avengers._isCheckedOut === 'true') {
- console.log("The book is checked out")
- } if (avengers._isCheckedOut === 'false') {
- console.log("This book is avaliable")
- } else
- console.log("ERROR");
- const newCd = new Cd('Ocean', 'Kasaija Akiiki');
- newCd.addSong('Billy Jean');
- newCd.addSong('Mafia');
- newCd.addSong('Yeke Yeke');
- //-----HERE IS THE CONSOLE.LOG FOR THE CD'S
- //console.log(newCd);
- const Test = new Catalog();
- Test.mediaList = historyOfEverything;
- Test.mediaList = avengers;
- Test.mediaList = tgg;
- Test.mediaList = newCd;
- //------HERE IS THE CONSOLE.LOG FOR THE OUTPUT
- //console.log(Test)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement