Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. class Media {
  2. constructor(title){
  3. this._title = title
  4. this._isCheckedOut = false
  5. this._ratings = []
  6. }
  7. get title() {
  8. return this._titel;
  9. }
  10. get isCheckedOut() {
  11. return this._isCheckedOut;
  12. }
  13. get ratings() {
  14. return this._ratings;
  15. }
  16. set isCheckedOut(value) {
  17. this._isCheckedOut = value;
  18. }
  19. toggleCheckOutStatus() {
  20. this.isCheckedOut = !this.isCheckedOut;
  21. }
  22. getAverageRating() {
  23. let ratingsSum = this.ratings.reduce((accumulator, rating) => accumulator + rating )
  24. return ratingsSum / this.ratings.length;
  25. }
  26. addRating(value) {
  27. this.ratings.push(value);
  28. }
  29. };
  30.  
  31. class Book extends Media {
  32. constructor(author, title, pages) {
  33. super(title)
  34. this._author = author
  35. this._pages = pages
  36. }
  37. get title() {
  38. return this._title;
  39. }
  40. get author() {
  41. return this._author;
  42. }
  43. get pages() {
  44. return this._pages;
  45. }
  46. };
  47.  
  48. class Movie extends Media {
  49. constructor(director, title, runTime) {
  50. super(title)
  51. this._director = director
  52. this._runTime = runTime
  53. }
  54. get title() {
  55. return this._title;
  56. }
  57. get director() {
  58. return this._director;
  59. }
  60. get runTime() {
  61. return this._runTime;
  62. }
  63. };
  64.  
  65. const historyOfEverything = new Book('Billy Bryson', 'A Short History of Nearly Everything', 554);
  66. historyOfEverything.toggleCheckOutStatus;
  67. console.log(historyOfEverything.isCheckedOut);
  68.  
  69. historyOfEverything.addRating(4);
  70. historyOfEverything.addRating(5);
  71. historyOfEverything.addRating(5);
  72.  
  73. historyOfEverything.getAverageRating;
  74. console.log(historyOfEverything.getAverageRating)
  75.  
  76. const speed = new Movie('Jan de Bont', 'Speed', 116);
  77. speed.toggleCheckOutStatus;
  78. console.log(speed.isCheckedOut);
  79.  
  80. speed.addRating(1);
  81. speed.addRating(1);
  82. speed.addRating(5);
  83.  
  84. console.log(speed.getAverageRating);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement