Newbie alert. I'm new to JavaScript. Love it so far. I'm having a bit of a problem I hope someone can help me with:
Here's my script in a .js file:
function human(name, age, gender){
this.name = name;
this.age = age;
this.gender = gender;
this.yearsToRetirement = function(){
return 65 - this.age;
};
}
var Steve = new human('Steve', 34, 'Male');
document.write(Steve.name + " " + Steve.age + " " + Steve.gender + Steve.yearsToRetirement);
But here's my browser output:
Steve 34 Malefunction (){ return 65 - this.age; }
As you may have guessed, I'm looking for there to be a "31" where we see function (){ return 65 - this.age; }
...What gives?
Any help is MUCH appreciated.
yearsToRetirementis a method of an object, so you have to call it withSteve.yearsToRetirement()