Advertisement
Liliana797979

hall - js adsvanced exam

Oct 1st, 2021
129
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.         throw new Error(`This event is already added!`);
  12.       } else {
  13.         this.events.push(title);
  14.         return `Event is added.`;
  15.       }
  16.     }
  17.  
  18.     close() {
  19.       this.events = [];
  20.       return `${this.name} hall is closed.`;
  21.     }
  22.  
  23.     toString() {
  24.       let result = [`${this.name} hall - ${this.capacity}`];
  25.       if (this.events.length > 0) {
  26.         result.push(`Events: ${this.events.join(", ")}`);
  27.       }
  28.       return result.join("\n");
  29.     }
  30.   }
  31.  
  32.   class MovieTheater extends Hall {
  33.     constructor(capacity, name, screenSize) {
  34.       super(capacity, name);
  35.       this.screenSize = screenSize;
  36.       this.events = [];
  37.     }
  38.  
  39.     close() {
  40.       return super.close() + "Аll screenings are over.";
  41.     }
  42.  
  43.     toString() {
  44.       let result = [super.toString()];
  45.       result.push(
  46.         `${this.name} is a movie theater with ${this.screenSize} screensize and ${this.capacity} seats capacity.`
  47.       );
  48.       return result.join("\n");
  49.     }
  50.   }
  51.  
  52.   class ConcertHall extends Hall {
  53.     constructor(capacity, name) {
  54.       super(capacity, name);
  55.       this.events = [];
  56.       this.performer = [];
  57.     }
  58.  
  59.     // hallEvent а не hallEvents както са го написали!!!
  60.     hallEvent(title, performers) {
  61.       if (this.events.includes(title)) {
  62.         throw new Error(`This event is already added!`);
  63.       } else {
  64.         this.events.push(title);
  65.         this.performer.push(performers);
  66.         return `Event is added.`;
  67.       }
  68.     }
  69.  
  70.     close() {
  71.       this.performer = [];
  72.       return super.close() + "Аll performances are over.";
  73.     }
  74.  
  75.     toString() {
  76.       let result = [super.toString()];
  77.       if (this.events.length > 0) {
  78.         for (const e of this.performer) {
  79.           result.push(`Performers: ${e.join(", ")}.`);
  80.         }
  81.       }
  82.       return result.join("\n");
  83.     }
  84.   }
  85.  
  86.   return { Hall, MovieTheater, ConcertHall };
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement