-
-
Save codecademydev/e49f11663d0c2c69c800f0d0ec63a65d to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(isCheckedOut){ | |
this.isCheckedOut = isCheckedOut ; | |
} | |
toggleCheckOutStatus(){ this._isCheckedOut =! this._ischeckedOut; | |
} | |
addRating(ratings){ | |
this._ratings.push(ratings); | |
} | |
getAverageRating(){ | |
let lengthOfArray = this._ratings.length; | |
let ratingsSum = this.ratings.reduce((currentSum,rating) => currentSum + rating, 0); | |
let average = Math.round(ratingsSum / lengthOfArray); | |
this._ratings = average; | |
} | |
}; | |
class Book extends Media{ | |
constructor(title, author, pages){ | |
super(title); | |
this._pages = pages; | |
this._author = author; | |
} | |
get pages(){return this._pages;} | |
get author(){return this.author;} | |
}; | |
class Movie extends Media{ | |
constructor(director,title,runTime){ | |
super(title); | |
this._director = director; | |
this._runtime = runtime; | |
} | |
get dirctor(){return this._director;} | |
get author(){return this._author;} | |
} | |
const historyOfEverything = new Book ('A Short History of Nearly Everything', 'Bill Bryson'); | |
historyOfEverything.toggleCheckOutStatus(); | |
console.log(historyOfEverything.isCheckedOut); | |
historyOfEverything.addRating(4); | |
historyOfEverything.addRating(5); | |
historyOfEverything.addRating(5); | |
historyOfEverything.getAverageRating(); | |
console.log(historyOfEverything.getAverageRating()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment