Advertisement
kstoyanov

03. People

Oct 16th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     class Employee {
  3.         constructor(name, age) {
  4.             if (new.target === Employee) {
  5.                 throw new Error("Canot instantiate directly.")
  6.             }
  7.             this.name = name;
  8.             this.age = age;
  9.             this.salary = 0;
  10.             this.tasks = [];
  11.         }
  12.  
  13.         work() {
  14.             let currentTask = this.tasks.shift();
  15.             console.log(this.name + currentTask);
  16.             this.tasks.push(currentTask);
  17.         }
  18.  
  19.         collectSalary() {
  20.             console.log(`${this.name} received ${this.salary} this month.`)
  21.         }
  22.     }
  23.  
  24.     class Junior extends Employee{
  25.         constructor(name, age) {
  26.             super(name, age);
  27.             this.tasks.push(` is working on a simple task.`);
  28.         }
  29.     }
  30.  
  31.     class Senior extends Employee{
  32.         constructor(name, age) {
  33.             super(name, age);
  34.             this.tasks.push(` is working on a complicated task.`);
  35.             this.tasks.push(` is taking time off work.`);
  36.             this.tasks.push(` is supervising junior workers.`);
  37.         }
  38.     }
  39.  
  40.     class Manager extends Employee{
  41.         constructor(name, age) {
  42.             super(name, age);
  43.             this.dividend = 0;
  44.             this.tasks.push(` scheduled a meeting.`);
  45.             this.tasks.push(` is preparing a quarterly report.`);
  46.         }
  47.  
  48.         collectSalary() {
  49.             console.log(`${this.name} received ${this.salary + this.dividend} this month.`)
  50.         }
  51.     }
  52.  
  53.     return {
  54.         Employee,
  55.         Junior,
  56.         Senior,
  57.         Manager
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement