29/33 olderAge is not a function


#1

hi all!

here's my code :smile:
i keep getting the message that my olderAge is not a function ,and i dont know whats wrong with the code :tired_face:

function Person (name, age) {
this.name = name;
this.age = age;
}
var ageDifference = function(person1, person2) {
return person1.age - person2.age;
};
var alice = new Person("Alice", 30);
var billy = new Person("Billy", 25);
console.log("The older person is " + olderAge(alice, billy));

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

help greatly appreciated :smile:


#2

your code is correct but the problem is that you are calling a function (olderAge) that has not been created yet. => The console.log should be the last line.


#3

@marcint,
There are 2 ways of defining a function

1

Assigning an anonymous Function to a variable
like

var olderAge = function (person1, person2) { };

2

Defining a so-called named Function
like

function olderAge(person1, person2) {  };

=========================================

Please read
= http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname?rq=1


#4

Guess i owe you a cupcake :smiley: ,Thanks !


#5

thanks for additional info, much appreciated :smile:


#6

n/p haha I love cupcake x)