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>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…