Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solveClasses() {
- class Developer{
- constructor ( firstName, lastName ){
- this.firstName=firstName;
- this.lastName=lastName;
- this.baseSalary = Number(1000);
- this.tasks = [];
- this.experience = Number(0);
- }
- addTask ( id, taskName, priority ){
- let task = {id, name: taskName, priority}; //да внимавам дали е name или taskName
- if(priority == 'high'){
- this.tasks.unshift(task);
- }
- else{
- this.tasks.push(task);
- }
- return `Task id ${id}, with ${priority} priority, has been added.`;
- }
- doTask(){
- let task = this.tasks.find(x => x.priority == 'high');
- if(!task){
- return `${task.name}`;
- }
- return `${this.firstName}, you have finished all your tasks. You can rest now.`;
- }
- getSalary(){
- return `${this.firstName} ${this.lastName} has a salary of: ${this.baseSalary}`;
- }
- reviewTasks(){
- let output = `Tasks, that need to be completed:\n`;
- for (let task of this.tasks) {
- output += `${task.id}: ${task.name} - ${task.priority}\n`;
- }
- return output.trim();
- }
- }
- class Junior extends Developer{
- constructor( firstName, lastName, bonus, experience ){
- super(firstName,lastName);
- this.bonus = Number(bonus);
- this.baseSalary = Number(1000) + this.bonus;
- this.taskName = [];
- this.experience = Number(experience);
- }
- learn(years){
- this.experience +=years;
- }
- }
- class Senior extends Developer{
- constructor( firstName, lastName, bonus, experience ){
- super(firstName,lastName);
- this.bonus = Number(bonus);
- this.baseSalary = Number(1000) + this.bonus;
- this.tasks = [];
- this.experience = Number(experience) + Number(5);
- }
- changeTaskPriority(taskId){
- let task = this.tasks.find(x => x.id == taskId);
- this.tasks = this.tasks.filter(x => x.id != taskId); //всички задачи без конкретната
- if(task.priority == 'high'){
- task.priority = 'low';
- this.tasks.push(task);
- }
- else{
- task.priority = 'high';
- this.tasks.unshift(task);
- }
- return task;
- }
- }
- return {
- Developer,
- Junior,
- Senior
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement