Passing Objects into Functions


#1

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


#2

What output you getting.


#3

nothing its comes up as blaNK


#4

Are you getting any syntax error?


#5

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


#6

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


#7

WIth that it now says: SyntaxError: Unexpected token (


#8

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


#9

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


#10

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


#11

`// 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 (


#12

You spelled the variable name wrong.


#13

How did i mess it up


#14

ageDifferece(alice,billy);


#15

Still says SyntaxError: Unexpected token (


#16

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


#17

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


#18

You call function like this
1) name of the function (ageDifferece)
2) double brackets "()"
3) inside the double brackets variables name (alice,billy)
4) ;


#19

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


#20

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