4. Listing Everybody


function list (){
var contactsLength = contacts.length ;

for (var i =0 ; i< contactsLength.length; i++); {
printPerson (contacts[i]);

Error message:
Oops, try again. It looks like your list function didn't console.log "Mary Johnson". Did you remember to call list(); after creating it?

Can anyone help pls?


Creating a function looks like this:

var functionName = function (optional parameter) {
//The codes runs inside of here

Not like this:

This is creating a method. We want to create a function.

No need of creating a variable called contactsLength. There is also a problem with your loop:

You call the variable contactsLength again with the method length when it is already the length of contacts. Instead, remove your variable contactsLength (I mean by deleting the whole line) and, instead of contactsLength.length you can put contacts.length. Much more simple.


Hi miniapple8888! Thanks so much for the help.After the ammendments, this is what I've got:

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

Error Message:
Oops, try again. Your code threw the following error when trying to call list(): TypeError: Cannot read property 'firstName' of undefined.

Don't mind, can help to see what's wrong?



Look here

Remove the semicolon between the parentheses and the curly brackets.


Got it!

Thanks a million!