Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
JavaScript Object planned output does't match

End of the code is:

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) + " year older than " + pete.firstname);

I wrote it:

pete = {
firstname: "Pete",
lastname: "Programmer",
age: 20
};
var cara = {
firstname: "Cara",
lastname: "Coder",
age: 30,
};
pete.fullname = function (){
console.log (pete.firstname + pete.lastname)
};
cara.fullname = function () {
console.log (cara.firstname + 
cara.lastname)
};

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) + " year older than " + pete.firstname);

Planned output:

Name: Pete Programmer   Age:20 Name: 
Cara Coder  Age:32
Cara is 12 years older than Pete

Don't understand why I have this output:

PeteProgrammer
Name: undefined Age:20
CaraCoder
Name: undefined Age:30
Cara is 10 years older than Pete
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In pete.fullname() and cara.fullname() functions you're doing console.log() instead of return. The code:

pete = {
firstname: "Pete",
lastname: "Programmer",
age: 20
};
var cara = {
firstname: "Cara",
lastname: "Coder",
age: 30,
};
pete.fullname = function (){
return pete.firstname + pete.lastname
}
cara.fullname = function () {
return cara.firstname + 
cara.lastname
};

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) + " year older than " + pete.firstname);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!