29. Try it out... Help Please :)


#1


Hello can you help me out please

https://www.codecademy.com/en/courses/spencer-sandbox/4/4?curriculum_id=506324b3a7dffd00020bf661#


Replace this line with your 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(age){
    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));


#2

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

Your function needs two parameters?
person1 and person2?but youre providing it age? (As you're using them inside the function, I hope you did not copied it from somewhere?)

also..
You need one more condition to check if ages are equal!

then rest of your code same as you wrote.


#3

Got it! Thank you very much


#4

Wow,that was fast! :thumbsup:


#5

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