28. Passing Objects into Functions


#1

This code shows me the error:

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!

I can't spot the problem.

// 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;
};
ageDifference(alice, billy);

#2

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

all you have to do here is call the function which calculates the age difference, not build another function

you already have a function calculating age difference:

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

#3

Yeah, I just tried that and it worked. Thanks


#4