28. Pas$ing Objects into Functions


#1


https://www.codecademy.com/courses/spencer-sandbox/4/3?curriculum_id=506324b3a7dffd00020bf661#


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

ageDifference();


#2

Try this:

That might help.


#3

Same exact error....


#4

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


#5

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


#6

check your ageDifference call.


#7

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


#8

Check it for what? Should i be calling differently?


#9

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


#10

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."


#11

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


#12

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


#13

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


#14

your function has two parameters:

var ageDifference = function(person1, person2)

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


#15

I assume i'm close with this:

var diff = ;

ageDifference(alice,billy);

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


#16

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


#17

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


#18

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