Introduction to objects lesson 29 code giving error


#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 olderAge = function(person1, person2){
    if(person1.age > person2.age){
        return person1.age;
    }
    else if(person2.age > person1.age){
        return person2.age;
    }
    else{
        return "Both are of same 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));


#2

Your code would normally be fine, but in the exercise then they want you to say that if person1.age is older than person2.age return person1.age else we want you to return person2.age. The problem is that you added in an else if statement which you don't have to do. You should just have it look like this.

if(person1.age > person2.age) {
      return person1.age;
} else {
      return person2.age;
}