Guest User

Untitled

a guest
Jan 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. //1
  2. class Media {
  3. //2 common property not set to a value
  4. constructor(title){
  5. //3 common properties
  6. this._title = title;
  7. this._isCheckedOut = false;
  8. this._ratings = [];
  9. }
  10. //4 create getters
  11. get title(){
  12. return this._title;
  13. }
  14. get isCheckedOut(){
  15. return this._isCheckedOut;
  16. }
  17. get ratings(){
  18. return this._ratings;
  19. }
  20.  
  21. //5 create a method
  22. toggleCheckOutStatus(){
  23. this._isCheckedOut = !this._isCheckedOut;
  24. }
  25. //6 calculate the ratings
  26. getAverageRating(){
  27. let ratingSum = this.ratings.reduce((total, currentValue) =>
  28. total + currentValue, 0);
  29. return ratings;
  30.  
  31. }
  32. //7
  33. addRating(nRatings){
  34. this.ratings.push(nRatings);
  35. }
  36.  
  37. }
  38.  
  39. //8 create book class
  40. class Book extends Media {
  41. //9 cosntructor accepts 3 arguments
  42. constructor(title, author, pages){
  43. //10 argument that parent constructor uses
  44. super(title);
  45. this._author = author;
  46. this._pages = pages;
  47.  
  48.  
  49. }
  50. //12
  51. get author(){
  52. return this._author;
  53. }
  54. get pages(){
  55. return this._pages;
  56. }
  57. addAuthor(newAuthor){
  58. this.author.push(newAuthor);
  59. }
  60. totalPages(nOfPages){
  61. this.pages.push(nOfPages);
  62. }
  63. }
  64. const historyOfEverything = new Book('A Short Histor of Nearly Everyting', 'Bill Bryson', 544, 90);
  65. console.log(historyOfEverything.title);
  66. console.log(historyOfEverything.author);
  67. console.log(historyOfEverything.pages);
  68. historyOfEverything.toggleCheckOutStatus();
  69. console.log(historyOfEverything.isCheckedOut);
  70. historyOfEverything.addRating(4);
  71. historyOfEverything.addRating(4);
  72. historyOfEverything.addRating(4);
  73. console.log('These are the ratings: '+ historyOfEverything.ratings);
  74.  
  75. //13 movies class
  76. class Movies extends Media {
  77. constructor(title, director, runTime){
  78. super(title);
  79. this._director = director;
  80. this._runTime = runTime;
  81. }
  82. }
Add Comment
Please, Sign In to add comment