Please Help on Intro to Objects1 28/33


#1

//I need help on the instantiation of ageDifference(alice,billy);

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
function ageDifference(person1,person2) {
return person1.age - person2.age;
}

var alice = new Person ("Alice", 30);
var billy = new Person ("Billy", 25);

// get the difference in age between alice and billy using our function
var diff = new ageDifference(alice,billy);
//Somebody please respond quickly.


#2

Hi, You need to use a function not a constructor because of your code should be :
var diff = ageDifference(alice,billy);


#3

Thanks pointphoton! It is done.