Building an Address Book (Needs Debugging)


#1


var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

// printPerson added here
var printPerson = function(contacts) {
    console.log(person.fistName + " " + person.lastName);
};
printPerson.contacts[0];


#2

here:

console.log(person.fistName + " " + person.lastName);

where is person coming from?

then the function call:

printPerson.contacts[0];

calling a function (printPerson) has the following general syntax:

functionName()

between the parentheses supply arguments to satisfy function parameters


#3

var contacts = [bob, mary];

// printPerson added here
var printPerson = function(contacts) {
console.log(contacts.fistName + " " + contacts.lastName);
};
printPerson(0);

Now it will log unidentified, which is better then what I had previously.


#4

your function is now good, just a slight tweak of your function call is needed:

printPerson(0);

you need to supply a contact (bob or mary) directly, or from your contacts array


#5

var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-7777",
email: "bob.jones@example.com"
};

var mary = {
firstName: "Mary",
lastName: "Johnson",
phoneNumber: "(650) 888-8888",
email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

// printPerson added here
var printPerson = function(contacts) {
console.log(contacts.fistName + " " + contacts.lastName);
};
printPerson(bob);

It's almost good, just not sure what it needs.


#6

Here's the result:
undefined Jones
undefined


#7

here:

console.log(contacts.fistName + " " + contacts.lastName);

you misspelled firstName


#8

Oh. and by the way. How do you call a function? Just state the function, or do you need to do something special?


#9

stating the function will do, look at this code with comments:

// creating function with parameter contacts
var printPerson = function(contacts) {
console.log(contacts.fistName + " " + contacts.lastName);
};
// calling function with argument bob
printPerson(bob);

#10

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