Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Media{
- constructor(title){
- this._title = title;
- this._isCheckedOut = false;
- this._ratings = [];
- }
- get title(){
- return this._title;
- }
- get isCheckedOut(){
- return this._isCheckedOut;
- }
- get ratings(){
- return this._ratings;
- }
- set isCheckedOut(checked){
- this._isCheckedOut = checked;
- }
- toggleCheckOutStatus(){
- this._isCheckedOut = !this._isCheckedOut;
- }
- getAverageRating(){
- let lengthOfArray = this._ratings.length;
- let result = this._ratings.reduce((accumulator, rating) => accumulator + rating, 0);
- return result/lengthOfArray;
- }
- addRating(newRating){
- this._ratings.push(newRating);
- }
- }
- //const newMedia = new Media('Jumanji', false, [5, 4, 5, 3, 2, 1,6, 7]);
- //console.log(newMedia.getAverageRating());
- //console.log(newMedia.isCheckedOut);
- class Book extends Media{
- constructor(title, author, pages){
- super(title);
- this._author = author;
- this._pages = pages;
- }
- get author(){
- return this._author;
- }
- get pages(){
- return this._pages;
- }
- }
- const historyOfEverything = new Book('Bill Bryson', 'A Short History of Nearly Everything', 544);
- historyOfEverything.toggleCheckOutStatus();
- console.log(historyOfEverything.isCheckedOut);
- historyOfEverything.addRating(4);
- historyOfEverything.addRating(5);
- historyOfEverything.addRating(6);
- console.log(historyOfEverything.getAverageRating());
- class Movie extends Media{
- constructor(title, director, runTime){
- super(title);
- this._director = director;
- this._runTime = runTime;
- }
- get director(){
- return this._director;
- }
- get runTime(){
- return this._runTime;
- }
- }
- const speed = new Movie('Jan deBont', 'Speed', 116);
- speed.toggleCheckOutStatus();
- console.log(speed.isCheckedOut);
- speed._ratings = [4, 3, 4];
- //speed.addRating(1);
- //speed.addRating(2);
- //speed.addRating(3);
- console.log(speed.getAverageRating());
Add Comment
Please, Sign In to add comment