13.object


#1

This code is not working!
"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
// Let's bring back alice and billy to test our new function
var alice = new Person("Alice", 30);
var billy = new Person("Billy", 25);
var olderAge=function(alice,billy)
{
if(alice>billy)
{
console.log('The older one is ' + olderAge(alice,billy))
}
}"


#2

Try this

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
// Let's bring back alice and billy to test our new function
var alice = new Person("Alice", 30);
var billy = new Person("Billy", 25);
var olderAge=function(person1,person2){
                if(ageDifference(person1, person2)>0){
                    return('The older one is ' + person1.age + " which is "+person1.name); 
                }
                else{
                   return('The older one is ' + person2.age+ " which is "+Person2.name); 
                }
            };
console.log(olderAge(alice, billy));

or
Test it here on labs