Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created March 21, 2020 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/52a6ce4a7b63839f734a85550a0958da to your computer and use it in GitHub Desktop.
Save codecademydev/52a6ce4a7b63839f734a85550a0958da to your computer and use it in GitHub Desktop.
Codecademy export
class Media{
costructor(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(){
this.isCheckedOut = !this.isCheckedOut;
}
getAverageRating(){
let sum = this.ratings.reduce((accumulator, currentValue) => accumulator + currentValue);
return (sum/this.ratings.length);
}
addRating(newRate){
this.ratings.push(newRate);
}
}
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){
super(title);
this._director = director;
this._runTIme = runTime;
}
get director() {
return this._director;
}
get runTime() {
return this._runTime;
}
}
let historyOfEverything = new Book('Bill Bryson', 'A Short History of Nearly Everything', 544);
historyOfEverything.toggleCheckOutStatus();
console.log(historyOfEverything.isCheckedOut);
let media = new Media ('sector');
console.log(media.ratings);
media.addRating(3);
//console.log(historyOfEverything.ratings);
//historyOfEverything.addRating(4);
//historyOfEverything.addRating(5);
//historyOfEverything.addRating(5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment