"olderAge" is not defined properly..not sure the issue though


// Our person constructor
function Person (name, age) {
this.name = name;
this.age = age;

// We can make a function which takes persons as arguments
// This one computes the difference in ages between two people
var ageDifference = function(person1, person2) {
return person1.age - person2.age;

// Make a new function, olderAge, to return the age of
// the older of two people
var olderAge = function(person1, person2)
if(person1.age > person2.age)
return person1.age;
else if(person1.age < person2.age)
return person2.age;
else if(person1.age === person2.age)
return age;

// Let's bring back alice and billy to test our new function
var alice = new Person("Alice", 30);
var billy = new Person("Billy", 25);

console.log("The older person is " + olderAge(alice, billy));

*The code prints but getting an error message..not sure what i did wrong.


Problem is here:

else if(person1.age === person2.age)
    return age;

Variable age is simply undefined. You should return age of person1 or person2.


Thanks dude! Definitely, a huge help!


You're very welcome :panda_face: