3. Displaying People- help me plz


#1


var contacts = [bob, mary];

function printPerson(person) {
console.log(person.firstName + " " + person.lastName); }
printPerson(contacts[0]);
printPerson(contacts[1]);

Oops, try again. Did you create a function called printPerson?
i did't understand waht wrong in this code


#2

Actually i have find out my error

var contacts = [bob, mary];

function printPerson(person) {
console.log(person.firstName + " " + person.lastName); }
printPerson(contacts[0]);
printPerson(contacts[1]);
this was my mistake i have changed
console.log(printPerson(contacts[0]));
console.log(printPerson(contacts[1]));


#3

But it's wrong! Why did you make function printPerson()? This function should print person's firstname and lastname. So

console.log(printPerson(contacts[0]));
console.log(printPerson(contacts[1]));

doesn't make sence because your function has console.log() method.
Your first code

function printPerson(person) {
   console.log(person.firstName + " " + person.lastName); 
}
printPerson(contacts[0]);
printPerson(contacts[1]);

is correct and should be accepted.


#4

i can understand but error showing in tat line and its not accepting :sweat:


#5

My code:

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

Try my code, should works. If not try to refresh / reset the lesson. Hope this help you.
Let me know about result please.


#6

ya it is working :slight_smile: thank you and will you please tell me that what mistake i have done in this code
var contacts = [bob, mary];

function printPerson(person) {
console.log(person.firstName + " " + person.lastName); }
printPerson(contacts[0]);
printPerson(contacts[1]);

why it not running


#7

Your code looks correct. Please post your full code and I'll try it.


#8

sorry i have deleted that code and i finished building an address book


#9

thank you for helping me :slight_smile:


#10

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