4. Listing everybody



There is no error message coming up and it technically does what it is supposed to, but it seems to call it twice?? In the console i get :

Bob Jones
Mary Johnson
Bob Jones
Mary Johnson

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<contacts.length; i++){



In some sections of this course, the course-checker Display's data
this you could then identify by placing two EXTRA code-line's:
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );

Thus use

console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );



In your for-loop, you are using "contacts.length" instead of "contactsLength". Try using the last one to see what happens. It worked fine for me.



I think its because when in your List function, you are telling the function to execute the printPerson function, which includes printing the persons name. Then, you call the List function and it does it again.

It seems Codecademy does this often for some reason.

Also, I don't understand the purpose of making a contactsLength variable. completely unnecessary step in my opinion.

The code works if you just don't make the contactsLength variable OR call the 'list' function



Please re-edit your Post

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

With Courtesy to stetim94

or even better use
= https://discuss.codecademy.com/t/how-do-i-format-code-in-my-posts/28351


I was wondering how to explain your fail (declare a variable "contactsLength" you arent using in your loop), and I just searched that your code can be just simplifier:

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

...and it works :slight_smile: