3. Displaying People


#1

The Editor tells me that this code is true:

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

var bob = [0, 1, 2];

console.log(bob[1]);
// prints 1

Can someone tell me if the Code is really right?


#2

@adam_spice,

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];
console.log( contacts );
// printPerson added here
var printPerson = function(person) {
    console.log(person.firstName + " " + person.lastName);
    };

var bob = [0, 1, 2];
console.log( contacts );
printPerson( contacts[0] );
console.log(bob[1]);

#3

This also works

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


#4

Here How I did.

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] );