Objects as Function Parameters - Where did I go wrong here?



As far as I can tell, mine is the same as examples of the correct codes I've seen on this message board. So why am I getting this error?
"Error Message: 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"

// 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 > person2) {
        return person1.age;
    else {
        return person2.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));



if (person1 > person2)

you are comparing persons, not the age of the person


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.