I am a beginner in the middle of a js basics course. I have a simple object related exercise and everything seems to be working except for the numeral values where the console prints the function instead of the wanted result.
// My code -->
const pete = {
firstname1: "Pete",
fullname1: "Pete Programmer",
age: 20,
firstname: function() {return this.firstname1},
fullname: function() {return this.fullname1},
age1: function() {return this.age1}
}
const cara = {
firstname1: "Cara",
fullname1: "Cara Code",
age1: 32,
firstname: function() {return this.firstname1},
fullname: function() {return this.fullname1},
age: function() {return this.age1}
}
// teachers uneditable code -->
console.log("Name: " + pete.fullname() + "\tAge: " + pete.age);
console.log("Name: " + cara.fullname() + "\tAge: " + cara.age);
console.log(cara.firstname + "is " + (cara.age - pete.age) + " years older than " + pete.firstname);
Console output:
"Name: Pete Programmer Age: 20"
"Name: Cara Code Age: function() {return this.age1}"
"function() {return this.firstname1}is NaN years older than function() {return this.firstname1}"
I havent been able to find the answer despite this looking like a simple problem.