Passing objects into functions 28


#1


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


Hello this is the error that shows me, I'm not sure of what I have to do in this exercise! Can you help me please

Oops, try again. Make sure to call the ageDifference function.

Replace this line with your code. 
// 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 = ageDifference;


#2

here:

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

calling a function requires parentheses:

functionName();

between the parentheses supply arguments to satisfy the function parameters if the function has parameters


#3

ageDifference() is a function and it needs argument! (2 arguments to be exact)

like this..

ageDifference(agr1,agr2);


#4

Thank you very much. Got it :slight_smile:


#5

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