Once again the logic escapes me! 29. Try it out


#1

Here is my error code:
Oops, try again. It looks like your olderAge function fails when the first Person is older! It should return the age of the older person.

Although my code runs and does give the right answer 30.

myCode

function Person (name, age) {
this.name = name;
this.age = age;

var ageDifference = function(person1, person2) {
return person1.age - person2.age;
};

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

var alice = new Person("Alice", 30);
var billy = new Person("Billy", 25);

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


#2

The Person constructor function is not closed. It needs a closing brace...

function Person(name, age) {
    this.name = name;
    this.age = age;
}

and,

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

The function is meant to be re-usable so we should be working with the parameters...

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

#3

Thank you, this solved my problem


#4

You're very good at this!!