Hitting a brick wall

In going through the FCC challenges, there have been times I’ve given in to looking at a hint after a few hours of no progress but I’ve been able to figure out the working and I’ve been able to move on. I might be being somewhat over-dramatic but I think I’ve found my nemesis and it’s got me in a choke hold and is pummeling my face…Nesting for loops.

I was doing okay with iterating odd/even numbers as well as counting backwards. But pop an array in there and I’ve got a problem. The key thing I don’t understand which may, or may not, be the key to my problem is the [i] in the following:

var arr=(10,9,8,7,6)

for (var i=0; i <arr.length;i++) {



I get that the variable is the top array. Then the loop initialises with the value 0. Then the condition is that it will continue cycling as for the length of the array as its maximum while adding 1 more  every loop. Now, it’s meant to output each part of said array but I don’t really understand the relation between the array and that final [i]. I definitely need to go back a couple of lessons and thrash it out. Nesting for loops?! I’m coming for you!!!!!! p.s if you can explain it to me, you have a friend for life!


4 thoughts on “Hitting a brick wall”

  1. thats how you refer to/reference which item, or index of the array you want.

    if you get rid of the arr[ ] parts, it will just log the numbers. if you put 3 in like this: arr[3] you should get 7, because arrays in most language are zero-based:

    item 0: 10
    item 1: 9
    item 2: 8
    item 3: 7
    item 4: 6

    if any of this doesnt perfectly fit what youre trying to learn, give me another example or hint and i will try again.

    if this answers your question, i made a friend? thats cool…

    Liked by 1 person

    1. Ah…I think I’m starting to get it slowly….thank you very, very much for taking the time to explain it to me. You do indeed have a new friend 😀

      Liked by 1 person

  2. no problem at all. heres the same program in another language. we will use the letter a instead of “arr,” because “arr” is already the name a command in the other language.

    #// split by spaces into an array:
    a = “10 9 8 7 6″ ; split a ” ”

    for i (1; 5; 1)
    now arrget a(i) ; print #// same as console.log(arr[i]);


    the command “next” is the same as } in java, javascript, c and c++


  3. I think your explanation is the correct and it really is that simple to me. I know there are many more applications for Loops but at it simplest forms you have explained it well I think but then I am a newb so take this for ehat it’s worth.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s