// 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() {
if(alice > billy){
return alice.age;
}
else{
return billy.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));
因此,在练习中,我需要做的是显示老年人的年龄。问题是它显示了年轻的年龄。这就是它所说的"年长的人是25岁和34岁。 。以下是我正在做的练习的链接:http://www.codecademy.com/courses/spencer-sandbox/4/4?curriculum_id=506324b3a7dffd00020bf661
答案 0 :(得分:0)
var olderAge = function() {
if(alice.age > billy.age){
return alice.age;
}
else{
return billy.age;
}
};
您可能还需要检查它们是否年龄相同。