Listing everybody instructions problem


why does it tell you in the instructions "All of the items in an array are numbered, starting at 0. To cycle through all of the elements of the array, create a for loop that cycles from 0 up to one less than the number of items in the contacts array."

if you do this then only one of the contacts will show (there are two now) and you get an error after you submit


To cover all corner cases for no matter how many contacts; while ensuring the for loop cycles from 0 up to one less than the number of items in the contacts array, I advise you add to the for loop expression,

i < contacts.length;


Yihaa, my first comment ever.

for (var i = 0; i < contactsLength; i++) {
    //  run this code within loop body

The for loop works like this, in this case it starts with the variable i which is 0, it then runs the code inside the loop body. After that it checks the variable, in this case, is it less than contactsLength? Yes is is, (because it's 0 and contactsLength is 1). Okay, increment by 1 and start over. Now variable i is 1, the code inside the loop body runs, then it checks again, is variable i less than contactsLengh? No, not any longer (because i is now 1), and the for loop stops.

Hope this helps, and please correct me if I'm wrong :slight_smile:


Spot on! However, it's contacts.length and not contactsLength.

Keep on! :slight_smile:


What is the final code????


Oh yes of course. I wasn't very clear that I defined the variable contactsLength earlier :slight_smile:

var contactsLength = contacts.length;



Where are you stuck? :slight_smile:


I dont know where i'm stuck


@jas364, please post your code and discribe the problem you have.


You're welcome.

Have fun coding! :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.