29/33


#1

Hello,

it tells me there is a problem, if person2 is older.

Could you please help me.

// 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 if (person1 < person2){
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));


#2

What is that problem?

If it isn't saying, then find out by calling your code and seeing if the result looks reasonable


#3

This is the exact reply i get, if i try to submit it:" Oops, try again. It looks like your olderAge function fails when the second Person is older! It should return the age of the older Person."


#4

I found my mistake i wrote person1 > person 2.

It has to be person1.age > person2.age and so on.


#5

Your age difference function can be argued to have a similar problem. It can produce negative results. Depending on the intention, that can be correct or sufficiently correct though.