Ads Here

Friday, September 3, 2021

Employee Experience Details - Class and Object & Date/ JavaScript

 

Employee Experience Details - Class and Object & Date

Write a JavaScript program to display the emplyoee experience details. 

The method displayEmployee must take an employee's name, designation & year of experience as its arguments and invoke the createEmployee method with these arguments.

The createEmployee method should create an Employee Object  out of the Employee class (object with values using a its parameterized constructor) and return the object to the caller - displayEmployee method.

Validate this object using instanceof operator and if valid, calculate the no of years in service (current year - year of joining) & return the same appended to a string (refer to console output).  Note: You may fetch the current year using the Date function & you may verify the correctness of your function by invoking it from within console.log.


console.log(displayEmployee("Jerold","Manager",15));


script:

class Employee 
{
 
}
function displayEmployee(name,designation,year_of_experience)
{
   var s = createEmployee(name,designation,year_of_experience);
   var sol=2020- s.year_of_experience;
   var res="";
     res+= s.name + " is serving the position of "+ s.designation + " since "+ sol;
     return res;
   
}
function createEmployee(name, designation, year_of_experience)
{
//fill code here
var employee={
    name: name ,
    designation: designation ,
    year_of_experience: year_of_experience
};
return employee;
}

function validateObject(employee)
{
//fill code here
var str= (employee instanceof Object );
if(str=== "true")
{
    
    displayEmployee();
}
}
console.log(displayEmployee);

No comments:

Post a Comment