Skip to content

Instantly share code, notes, and snippets.

@codecademydev codecademydev/app.js Secret

Created Apr 20, 2020
Embed
What would you like to do?
Codecademy export
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(value){
this._isCheckedOut=value;
}
toggleCheckOutStatus(){
if (this.isCheckedOut === false){
isCheckedOut(true);
} else if (this.isCheckedOut === true){
isCheckedOut(false);
}
}
getAverageRating(){
let ratingsSum = this._ratings.reduce((currentSum, rating) => currentSum + rating, 0);
const lengthRatings = this.ratings.length;
return ratingsSum/lengthRatings;
}
addRating(rate){
this._ratings.push(rate);
}
};
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;
}
};
class Movie extends Media{
constructor (title,director,runTime){
super(title);
this._director = director;
this._runTime = runTime;
}
get director(){
return this._director = director;
}
get runTime(){
return this._runTime;
}
};
const historyOfEverything = new Book('A Short History of Nearly Everything','Bill Bryson',544);
console.log(historyOfEverything);
historyOfEverything.toggleCheckOutStatus();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.