4. Listing Everybody


#1

Whats going wrong here? I just do not see the error...:sweat:

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

list ();


#2

@robertkooyman,
Have a read, and look at the setup of the FOR-loop
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for


#3

Just discovered it myself at the very same moment. ; instead of ,

Thanks for the feedback! :slight_smile:


#4

On the same issue, does anyone know why it prints out both names twice?
The console returns:

Bob Jones
Mary Johnson
Bob Jones
Mary Johnson


#5

@blindpupil,

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

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

and look on which side the output created.....