I'm stuck on this (29. Try It Out!)


My error code is as follows: "ReferenceError: person1 is not defined"

I checked over it and i guess I'm not catching what's wrong?

// 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(alice, billy) {
    if(person1.age > person2.age) {
        return person1.age;
    }else if(person1.age < person2.age) {
        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));


Here, you aren't using the "person1" and "person2" as your arguments, but you use them in the body of olderAge.


So, it should look like

var olderAge = function(person1, person2)


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

Unless i now got it entirely wrong


okay i have a entirely new problem dealing with the same block of code

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

giving the following error:
"Oops, try again. It looks like your olderAge function fails when both Persons have the same age. It should return the age!"

The console returned the age of the older person


You'd need to use === for one of the else if statements. Then you just pick whichever one you want to return.


You are missing statement where they both have same age

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


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