3. Displaying People


#1

Could anyone check 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];


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

printPerson(0);
printPerson(1);

Error message:

--> Oops, try again. Did you create a function called printPerson?


Can someone check my code too plz
#2

1- Delete contacts[] but don't delete person from this line:

2- put the numbers inside contacts[]


#3

It worked!


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


Thanks a lot! :slight_smile:


#4

Your welcome :slight_smile:


#5

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