3/6 It seems that the instructions are wrong


#1

var printPerson = function(person) {
console.log(contacts.firstName + " " + contacts.lastName);
}
printPerson(bob);
printPerson(mary);


The instructions say "Define a function called printPerson that takes a parameter called person."
The only parameter is called contacts. If i call it person it doesn't work. Is there something I'm missing.


#2

Try 'person.firstName' and 'person.lastName' instead of 'contacts.firstName' and 'contacts.lastName'.
Hope that helped! :smile:


#3

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([0],[1]) { <----// Look at this very carefully!!

console.log(bob.firstName + " " + bob.lastName);
printPerson(contacts[0].firstName);
console.log(mary.firstName + " " + mary.lastName);
printPerson(contacts[1].lastName);

};
This code worked for me...


#4

hey I've got answer for this

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 (person){
console.log(person.firstName +" " + person.lastName);
console.log(person.firstName +" "+ person.lastName);
}
printPerson(contacts[0]);
printPerson(contacts[1]);


#5

This is the way I did it and it seems to work fine. Although there may be a better way than this...

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(person){
console.log (person.firstName + " " + person.lastName);
};

printPerson(contacts[0]);
printPerson(contacts[1]);

It will print on the console:
Bob Jones
Mary Johnson


#6

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(person){
    console.log(person.firstName + " " + person.lastName);
}


printPerson(contacts[0]);
printPerson(contacts[1]);

Instructions are good and this is whole code so people can see what is going on.
When you call your function, you need to pass to it 1. and 2. array object by writting function(array[object_position_in_this_array]);