Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1
- class Media {
- //2 common property not set to a value
- constructor(title){
- //3 common properties
- this._title = title;
- this._isCheckedOut = false;
- this._ratings = [];
- }
- //4 create getters
- get title(){
- return this._title;
- }
- get isCheckedOut(){
- return this._isCheckedOut;
- }
- get ratings(){
- return this._ratings;
- }
- //5 create a method
- toggleCheckOutStatus(){
- this._isCheckedOut = !this._isCheckedOut;
- }
- //6 calculate the ratings
- getAverageRating(){
- let ratingSum = this.ratings.reduce((total, currentValue) =>
- total + currentValue, 0);
- return ratings;
- }
- //7
- addRating(nRatings){
- this.ratings.push(nRatings);
- }
- }
- //8 create book class
- class Book extends Media {
- //9 cosntructor accepts 3 arguments
- constructor(title, author, pages){
- //10 argument that parent constructor uses
- super(title);
- this._author = author;
- this._pages = pages;
- }
- //12
- get author(){
- return this._author;
- }
- get pages(){
- return this._pages;
- }
- addAuthor(newAuthor){
- this.author.push(newAuthor);
- }
- totalPages(nOfPages){
- this.pages.push(nOfPages);
- }
- }
- const historyOfEverything = new Book('A Short Histor of Nearly Everyting', 'Bill Bryson', 544, 90);
- console.log(historyOfEverything.title);
- console.log(historyOfEverything.author);
- console.log(historyOfEverything.pages);
- historyOfEverything.toggleCheckOutStatus();
- console.log(historyOfEverything.isCheckedOut);
- historyOfEverything.addRating(4);
- historyOfEverything.addRating(4);
- historyOfEverything.addRating(4);
- console.log('These are the ratings: '+ historyOfEverything.ratings);
- //13 movies class
- class Movies extends Media {
- constructor(title, director, runTime){
- super(title);
- this._director = director;
- this._runTime = runTime;
- }
- }
Add Comment
Please, Sign In to add comment