Advertisement
divanov94

Untitled

Oct 16th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution() {
  2.     class Hall {
  3.         constructor(capacity, name) {
  4.             this.capacity = capacity;
  5.             this.name = name;
  6.             this.events = [];
  7.         }
  8.  
  9.         hallEvent(title) {
  10.             if (!this.events.includes(title)) {
  11.                 this.events.push(title);
  12.                 return 'Event is added.'
  13.             }else {
  14.                 throw new Error('This event is already added!');
  15.             }
  16.  
  17.         }
  18.         close(){
  19.             this.events=[];
  20.             return `${this.name} hall is closed`;
  21.         }
  22.         toString(){
  23.             let output=[];
  24.             output.push(`${this.name} hall - ${this.capacity}`);
  25.             if(this.events.length>0){
  26.                 output.push(`Events: ${this.events.join(", ")}`);
  27.             }
  28.             return output.join('\n');
  29.         }
  30.     }
  31.     class MovieTheater extends Hall{
  32.         constructor(capacity,name,screenSize) {
  33.             super(capacity,name);
  34.             this.events=[];
  35.             this.screenSize=screenSize;
  36.         }
  37.         close(){
  38.             return `${super.close()}All screenings are over.`
  39.         }
  40.         toString() {
  41.             return `${super.toString()}\n${this.name} is a movie theather with ${this.screenSize} screensize and ${this.capacity} seats capacity.`;
  42.  
  43.         }
  44.  
  45.     }
  46.     class ConcertHall extends Hall{
  47.         constructor(capacity,name){
  48.             super(capacity,name);
  49.             this.events=[];
  50.             this.performers=[];
  51.         }
  52.         hallEvent(title,performers){
  53.  
  54.  
  55.             if(this.events.includes(title)){
  56.                 throw new Error('This event is already added!');
  57.             }
  58.                this.events.push(title);
  59.                this.performers.push(...performers);
  60.                return `Event is added.`;
  61.         }
  62.         close(){
  63.             this.performers=[];
  64.             return `${super.close()} All performances are over.`
  65.         }
  66.         toString() {
  67.             let output=[super.toString()];
  68.             if(this.performers.length>0){
  69.                 output.push(`Performers: ${this.performers.join(', ')}.`);
  70.  
  71.  
  72.             }
  73.             return output.join('\n')
  74.  
  75.         }
  76.     }
  77.  
  78.  
  79.     return {
  80.         Hall,
  81.         MovieTheater,
  82.         ConcertHall,
  83.     }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement