Advertisement
ralichka

Untitled

Oct 24th, 2020
1,761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solveClasses() {
  2.  
  3.     class Developer{
  4.         constructor ( firstName, lastName ){
  5.             this.firstName=firstName;
  6.             this.lastName=lastName;
  7.             this.baseSalary = Number(1000);
  8.             this.tasks = [];
  9.             this.experience = Number(0);
  10.            
  11.         }
  12.         addTask ( id, taskName, priority ){
  13.             let task = {id, name: taskName, priority}; //да внимавам дали е name или taskName
  14.             if(priority == 'high'){
  15.                 this.tasks.unshift(task);
  16.             }
  17.             else{
  18.                 this.tasks.push(task);
  19.             }
  20.             return `Task id ${id}, with ${priority} priority, has been added.`;
  21.  
  22.         }
  23.  
  24.         doTask(){
  25.             let task = this.tasks.find(x => x.priority == 'high');
  26.             if(!task){
  27.                 return `${task.name}`;
  28.             }
  29.             return `${this.firstName}, you have finished all your tasks. You can rest now.`;
  30.         }
  31.  
  32.         getSalary(){
  33.             return `${this.firstName} ${this.lastName} has a salary of: ${this.baseSalary}`;
  34.         }
  35.  
  36.         reviewTasks(){
  37.             let output = `Tasks, that need to be completed:\n`;
  38.            
  39.             for (let task of this.tasks) {
  40.                 output += `${task.id}: ${task.name} - ${task.priority}\n`;
  41.             }
  42.             return output.trim();
  43.         }
  44.     }
  45.  
  46.     class Junior extends Developer{
  47.         constructor( firstName, lastName, bonus, experience ){
  48.             super(firstName,lastName);
  49.             this.bonus = Number(bonus);
  50.             this.baseSalary = Number(1000) + this.bonus;
  51.             this.taskName = [];
  52.             this.experience = Number(experience);
  53.         }
  54.  
  55.         learn(years){
  56.             this.experience +=years;
  57.         }
  58.     }
  59.  
  60.     class Senior extends Developer{
  61.         constructor( firstName, lastName, bonus, experience ){
  62.             super(firstName,lastName);
  63.             this.bonus = Number(bonus);
  64.             this.baseSalary = Number(1000) + this.bonus;
  65.             this.tasks = [];
  66.             this.experience = Number(experience) + Number(5);
  67.         }
  68.  
  69.         changeTaskPriority(taskId){
  70.            
  71.            
  72.             let task = this.tasks.find(x => x.id == taskId);
  73.             this.tasks = this.tasks.filter(x => x.id != taskId); //всички задачи без конкретната
  74.            
  75.             if(task.priority == 'high'){
  76.                 task.priority = 'low';
  77.                 this.tasks.push(task);
  78.             }
  79.             else{
  80.                 task.priority = 'high';
  81.                 this.tasks.unshift(task);
  82.             }
  83.             return task;
  84.  
  85.         }
  86.        
  87.     }
  88.    
  89.  
  90.     return {
  91.         Developer,
  92.         Junior,
  93.         Senior
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement