Need help PASSING OBJECTS into functions!


function Person (name, age) { = 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;

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 = (billy,alice){
 return ageDifference person1.age - person2.age


You can call a function like so,

function_name(a_argument_you_want_to_pass_to_it, and_another)

In this case, the arguments you want to pass are billy and alice.


When the ageDifference function was created it was setup to expect two pieces of data to be sent to it. That's this part here: (person1, person2)

To use the function, you call it, and send it the pieces of data that it is expecting, like this:


If you also want to see the results you can log the function call, like this:


Do you see how these pieces fit together now?


I got it running thanks


how did u get it?
can u expain please ?
and share ur code also


Have look at my earlier post that explains how to use your ageDifference function. Instead of creating a new function, use that one instead.