Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- class Playable {
- constructor(title, author) {
- this.id = Math.random() * 100;
- this.title = title;
- this.author = author;
- }
- get title(){
- return this._title;
- }
- set title(value){
- this._title = value;
- }
- get author(){
- return this._author;
- }
- set author(value){
- this._author = value;
- }
- play(){
- return "[" + this.id.toString() + "]." + " " +"[" + this.title.toString() +"]" + " - " +"[" + this.author.toString()+"]";
- }
- }
- class Audio extends Playable {
- constructor(title, author, length) {
- super(title, author);
- this.length = length;
- }
- get length(){
- return this._length;
- }
- set length(value){
- if (value <= 0){
- throw "Length lower or equal to 0"
- }
- this._length = value
- }
- play(){
- return super.play() +" - ["+this.length.toString()+"]"
- }
- }
- class Video extends Playable {
- constructor(title, author, imdbRating){
- super(title , author);
- this.imdbRating = imdbRating;
- }
- get imdbRating(){
- return this._imdbRating;
- }
- set imdbRating(value){
- if(value <1 || value >5){
- throw 'Value is under 1 or above 5'
- }
- this._imdbRating = value;
- }
- play(){
- return super.play() + " - ["+this.imdbRating.toString()+"]";
- }
- }
- const module = {
- getPlayer: function (name){
- // returns a new player instance with the provided name
- },
- getPlaylist: function(name){
- //returns a new playlist instance with the provided name
- },
- getAudio: function(title, author, length){
- //returns a new audio instance with the provided title, author and lengthu
- return new Audio(title, author, length);
- },
- getVideo: function(title, author, imdbRating){
- //returns a new video instance with the provided title, author and imdbRating
- return new Video(title, author , imdbRating);
- },
- };
- class Playlist {
- constructor(name) {
- this.id = Math.random() * 100;
- this.name = name;
- this.playlist = [];
- }
- get name(){
- return this._name;
- }
- set name(value){
- this._name = value;
- }
- addPlayable(playable){
- this.playlist.push(playable);
- return this;
- }
- }
- return module;
- }
- let p = solve().getVideo("kniga za djunglata", "liliIvanova", 2);
- console.log(p.play());
- console.log(p);
- module.exports = solve;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement