Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. function solve() {
  2. class Playable {
  3. constructor(title, author) {
  4. this.id = Math.random() * 100;
  5. this.title = title;
  6. this.author = author;
  7. }
  8. get title(){
  9. return this._title;
  10. }
  11. set title(value){
  12. this._title = value;
  13. }
  14.  
  15. get author(){
  16. return this._author;
  17. }
  18. set author(value){
  19. this._author = value;
  20. }
  21.  
  22. play(){
  23. return "[" + this.id.toString() + "]." + " " +"[" + this.title.toString() +"]" + " - " +"[" + this.author.toString()+"]";
  24. }
  25. }
  26.  
  27. class Audio extends Playable {
  28. constructor(title, author, length) {
  29. super(title, author);
  30. this.length = length;
  31. }
  32. get length(){
  33. return this._length;
  34. }
  35. set length(value){
  36. if (value <= 0){
  37. throw "Length lower or equal to 0"
  38. }
  39. this._length = value
  40. }
  41. play(){
  42. return super.play() +" - ["+this.length.toString()+"]"
  43. }
  44. }
  45. class Video extends Playable {
  46. constructor(title, author, imdbRating){
  47. super(title , author);
  48. this.imdbRating = imdbRating;
  49. }
  50. get imdbRating(){
  51. return this._imdbRating;
  52. }
  53. set imdbRating(value){
  54. if(value <1 || value >5){
  55. throw 'Value is under 1 or above 5'
  56. }
  57. this._imdbRating = value;
  58. }
  59. play(){
  60. return super.play() + " - ["+this.imdbRating.toString()+"]";
  61. }
  62. }
  63. const module = {
  64. getPlayer: function (name){
  65. // returns a new player instance with the provided name
  66. },
  67. getPlaylist: function(name){
  68. //returns a new playlist instance with the provided name
  69. },
  70. getAudio: function(title, author, length){
  71. //returns a new audio instance with the provided title, author and lengthu
  72. return new Audio(title, author, length);
  73. },
  74. getVideo: function(title, author, imdbRating){
  75. //returns a new video instance with the provided title, author and imdbRating
  76. return new Video(title, author , imdbRating);
  77. },
  78. };
  79.  
  80. class Playlist {
  81. constructor(name) {
  82. this.id = Math.random() * 100;
  83. this.name = name;
  84. this.playlist = [];
  85. }
  86. get name(){
  87. return this._name;
  88. }
  89. set name(value){
  90. this._name = value;
  91. }
  92. addPlayable(playable){
  93. this.playlist.push(playable);
  94. return this;
  95. }
  96. }
  97.  
  98. return module;
  99. }
  100.  
  101. let p = solve().getVideo("kniga za djunglata", "liliIvanova", 2);
  102. console.log(p.play());
  103. console.log(p);
  104. module.exports = solve;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement