29. Try it Out!


#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) {
    console.log(person1)    
    }
    else {
    console.log(person2)
    }
};
// 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));


My code keeps saying "Oops, try again. Your olderAge function seems to be returning something other than a number. The function should return the AGE of the older person" and it prints 
{ name: 'Alice', age: 30 }
The older person is undefined
{ name: 'Michael', age: 25 }


#2

What's your error message?
Can I have the link to the exercise as well?
What do you expect the code to do, and what do you need help with? I just need an actual question so that I can guide you to the answer :slight_smile:
Oh and I like your pfp.


#3

be careful on what you're printing. person1 and person2 are objects. you print an object, you get everything it got.

if you need only to print 1 attribute, AGE for example, use:
console.log(person1.age)


#4

Thank you for the help :grin:


#5

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