4.Listing EveryBody PLS HELP!



Whats the problem of this code?
its 2 times logging out Names of contacts.No other information.

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

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);

var list = function () {
    var contactsLength = contacts.length;
    for (i=0;i<contactsLength;i++) {


Because of this..

the other o/p that shown is actually tested and printed by CC interpreter!!


And what i must write to get correct working code?


Your code is correct!
No need to change anything.

Other part of your question..

its 2 times logging out Names of contacts.No other information.

You can see your printPerson() function access person name(variable) and just excess first and last name (and prints it so you'll see only name and no other information). so your program works as it intended to!


And for additional information of person i must change console line to print out email,phoneNumber and etc. yeah?


If you go line and by line and read what your program does then you might find that Your program has only one work to do..

Yourlist function works on contacts Array and loops over contacts and gives contacts (which is an Array) items to printPerson() and what printPerson() function does is to print the first and last name by concatenating them.

You can make changes so your code print other information but this exercise is not meant to implement those things. You can add functionality by your own. (you may try to do this on CC editor but It may throw an error as CC's only instructed to print the names in this exercise.)


OK i understand at last.Thnx a lot :wink:


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