Build a Library Feedback

Hey guys !!
I hope everyone good :smiling_face_with_three_hearts: :smiling_face_with_three_hearts: , check out my final project of Building Library , without bugs or problems , it’s my own code , and i want to share it with you guys to combine my code with yours .

class Media {
  constructor(title) {
    this._title = title;
    this._isCheckOut = false;
    this._ratings = [];
  }

  get title() {
    return this._title;
  }

  get isCheckOut() {
    return this._isCheckOut;
  }

  set isCheckOut(newValue) {
    this._isCheckOut = newValue;
  }

  get ratings() {
    return this._ratings;
  }

  toggleCheckOutStatus() {
    this._isCheckOut = !this._isCheckOut;
  }
  getAverageRating() {
    let calcRatingSum = this._ratings.reduce((currentSum, rating) => (currentSum + rating) / this._ratings.length);
  }

  addRating(newRating) {
    this._ratings.push(newRating);
  }
}


class Book extends Media {
  constructor(author, title, pages) {
    super(title);
    this._author = author;
    this._title = title;
    this._pages = pages;
    //this._isCheckOut = isCheckOut;
    this._ratings = [8];
  }

  get author() {
    return this._author;
  }

  get title() {
    return this._title;
  }

  get pages() {
    return this._pages;
  }

  /*get isCheckOut() {
    return this._isCheckOut;
  }*/

  get ratings() {
    return this._ratings;
  }

  getAverageRating() {
   console.log(this._ratings.reduce((currentSum, rating) => (currentSum + rating) / this._ratings.length) + '%');
  }
  toggleCheckOutStatus() {}
  addRating(newRating) {
    this._ratings.push(newRating);
  }
}

class Movie extends Media {
  constructor(director, runTime, title, ratings, isCheckOut){
    super(title, isCheckOut);
    this._director = director;
    this._runTime =  runTime;
    this._isCheckOut = false;
    this._ratings = [];
  }

  get director() {
    return this._director;
  }

  get runTime() {
    return this._runTime;
  }

  get isCheckOut() {
    return this._isCheckOut;
  }

  get ratings() {
    return this._ratings;
  }

  getAverageRating() {
    /*console.log(this._ratings.reduce((currentSum, rating) => (currentSum + rating) / this._ratings.length) + '%');*/
    let calcRating = this._ratings.reduce((currentVal, rating) => (currentVal + rating) / this._ratings.length);
    let finalResult = Math.floor(calcRating);
    console.log(finalResult + '%');
  }
  toggleCheckOutStatus() {
    this._isCheckOut = !this._isCheckOut;
  }
  addRating(newRating) {
    this._ratings.push(newRating);
  }
}

const historyOfEverything = new Book('Bill Bryson', 'A Short History of Nearly Everything', 544);

const speed = new Movie('Jan de Bont', 'Speed', 116);

speed.toggleCheckOutStatus();
speed.addRating(1);
speed.addRating(1);
speed.addRating(5);
speed.getAverageRating();
console.log(speed._isCheckOut);

historyOfEverything.toggleCheckOutStatus();
historyOfEverything.addRating(4);
historyOfEverything.addRating(5);
historyOfEverything.addRating(5);
historyOfEverything.getAverageRating();
console.log(historyOfEverything._ratings);
console.log(historyOfEverything._isCheckOut);
//console.log(historyOfEverything._rating);
1 Like