28. Pas$ing Objects into Functions



"Oops, try again. It looks like the value of diff is not a number! Make sure you are setting it equal to ageDifference(alice,billy). Make sure not to put quotes around alice and billy!" Im not quite sure how i put together the new function incorrectly.

// 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 diff = function(alice, billy) {
    return alice.age - billy.age;



Try this:

That might help.


Same exact error....


var diff = function(alice, billy) {
return alice.age -= billy.age;
You need to do the same thing here.


Changing both "-"s to "-=" made the same error.


check your ageDifference call.


this comment:

// get the difference in age between alice and billy using our function

it tells you to get the age difference by using our function, in other words you need to call ageDifference function with the right arguments, no need to create a diff function


Check it for what? Should i be calling differently?


you don't supply the right arguments when calling the function, see my answer:


They created the beginning of the new function for me.

var diff =

they put that there. The instructions "We have created two example people, alice and billy. Complete line 17 by calling ageDifference and saving the result in our global diff variable."


So im calling incorrectly, ok, Ill look into calling it with the proper arguments.


oops, sorry.

No, that is not the beginning of a new function, its a variable in which you can store the result of calling the ageDifference function


Oh curious, hmmmm. Ill try and look back and see how to call the function with that.


your function has two parameters:

var ageDifference = function(person1, person2)

this means when you call the function, you need to supply two arguments


I assume i'm close with this:

var diff = ;


i just need to figure out the rest of the variable?


Just kidding. Just deleting the ; made it pass. haha


that should be one line, this will store what the function returns in the diff variable


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.