Try it Out!


#1

`// 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 oldAge = function(person1, person2) {
return
};
// 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));`

Help :disappointed:
@mtf @amanuel2 @albionsrefuge


#2

We can complete this in a couple of ways, depending whether we wish to use the ageDifference function, or not.

// with ageDifferenc()
// note function name

var olderAge = function (person1, person2) {
    if (ageDifference(person1, person2) > 0) {
        return person1.age
    }
    return person2.age;
};

// without ageDifference()

var olderAge = function (person1, person2) {
    if (person1.age > person2.age) {
        return person1.age;
    }
    return person2.age;
};

#3

in the oldAge function...
(amend this to olderAge so it prints out the result in the command window via the last line of code console.log..)...
you need to incorporate .... if/else so that the code upon calculating the age difference can then return the correct result

have a look at the code I wrote for this task and that should make it clearer for you.

I am only just ahead of you and still learning so my code writing format is still very elementary and because its not that great it could be written better.

Though the code works to answer the task, I would use it as a guideline and then see how you want to write it yourself to get the outcome for this task.

// 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
function olderAge (person1, person2) {
if(person1.age > person2.age) {
return person1.age;
}
else if (person1.age < person2.age) {
return person2.age;
}
else {
return person1.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));