Passing Objects into Functions

`// 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;
}

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 ageDifference = function(person1, person2) {
return 30 - 25;
}`
What am i doing worng

What output you getting.

nothing its comes up as blaNK

Are you getting any syntax error?

no ths is what i am gettiing
Make sure to call the ageDifference function.

You didn’t called the function on Alice and Billy
ageDifference(Alice,billy);

WIth that it now says: SyntaxError: Unexpected token (

In that function I wrote Alice did you write the first letter in lowercase?

No, i copy what you do right into and now it says SyntaxError: Unexpected token (

You need to write your person var(alice and billy) exact same way you defined it.
ageDifferece(alice,billy);

`// 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;
}

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 ageDifference (Alice,Billy); {
return 30 - 25;
}`
New code and it still says SyntaxError: Unexpected token (

You spelled the variable name wrong.

How did i mess it up

ageDifferece(alice,billy);

Still says SyntaxError: Unexpected token (

Ok just write one thing how you call the ageDifferece function.

var ageDifference = function(person1, person2) { return person1.age - person2.age; }

You call function like this

  1. name of the function (ageDifferece)
  2. double brackets “()”
  3. inside the double brackets variables name (alice,billy)
  4. ;

Is this it?
`// 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;
}

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 ageDifference = function(Alice, Billy) {
return 30 - 25;
}`

In second last line you don’t have to tell it return 30-25.