简体   繁体   中英

create a custom method get experience of the employee model by considering the year of joining as parameter

Create a custom method get experience of the employee model by considering the year of joining as parameter

Create Employee model with properties employee_id, name, year_of_joining and experience

From the question asked by Hacker Rank there are few test cases out of that one generally fails.

which says expected 22 instead of 0.

So the complete answer is posted here.

So the Answer to the question is

var Employee = Backbone.Model.extend({ //Write your code here

default:
{
   employee_id:1111,
   name:'Sarah Roe',
   year_of_joining:1999,
   address:'ABC Street',
   experience: null
},
getExperience: function (year_of_joining) {
  var current_date = new Date();
  var current_year = current_date.getFullYear();
  var calculated_exp = (current_year) - (year_of_joining);

  *this.set({ experience: calculated_exp });*
  return calculated_exp;
}

});

var employee = new Employee({ employee_id: 721, name: "Shrikrishna", year_of_joining: 1999, experience: 22}); //please add properties and values of Employee model //employee.set({'experience': employee.get('year_of_joining')}); alert("Experience of " + employee.get("name") + " is " + employee.getExperience(employee.get('year_of_joining')) + " years");

</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM