4. Listing Everybody


#1

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

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

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?


#2

@zainuddeen11
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.


#3

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++); {
printPerson(contacts[i]);
}
};
list();

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?


#4

@zainuddeen11

Look here

Remove the semicolon between the parentheses and the curly brackets.


#5

Got it!

Thanks a million!