29/33 whats wrong?


#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){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));

Oops, try again. There was a problem with your syntax.


#2

never mind i fixed it


#3

This happens quite often that you fix the problem right after posting a questions. In this case it would be great if you could mention how you fixed it and give that answer the solution button so that you don't confuse further readers. Thank you.


#4

My code:

 // 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 ("The older person is " +person1.age);
        }
        else if (person1.age < person2.age)
        {
            return ("The older person is " + person2.age);
        }
        else (person1.age === person2.age)
        {
            return ("Both ages are the same");
        }
    };

    // Let's bring back alice and billy to test our new function
    var alice = new Person("Alice", 25);
    var billy = new Person("Billy", 25);
    console.log(olderAge(alice, billy));

If you want to pass to the next stage, all you should do is copy and paste the following:
// 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 {
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));


#5

rmansour i wanted to use "My code:" from your post but when i did it told me something about
Your olderAge function seems to be returning something other than a number. The function should return the AGE of the older person