4. Listing Everybody..Right but I don't thinks so!


#1

Evening,

Ok so i've done this excercise, getting the green button but I don't think my coding is right for some reason, I was hoping you guys could confirm it. Also, the contacts are getting printed twice on the screen.

And lastly, what is the list(); duty in the code, because won't the for code, loop through the data without it?

P.s when I remove the list(); the two contacts get printed out once.

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;
    for(var i = 0; i < contacts.length; i++) {
    printPerson(contacts[i]);
    }
}

list();


#2

This post was flagged by the community and is temporarily hidden.


#3

This post was flagged by the community and is temporarily hidden.


#4

I don't think there is anything you can change because I tried to change my code but it is still coming out with the the sets of names. Mine is the same as yours. List basically just lists what you put down so basically like this example

var list = [
{ date: '12/1/2011', reading: 3, id: 20055 },
{ date: '13/1/2011', reading: 5, id: 20053 },
{ date: '14/1/2011', reading: 6, id: 45652 }
];
and then access it:

alert(list[1].date);


#5

This post was flagged by the community and is temporarily hidden.


#6

I was just showing an example for a list that he was talking about.


#7

This post was flagged by the community and is temporarily hidden.


#8

It is supposed to print out the dates that are there.


#13