Loop for Loop



Hey CC Squad, I was hoping to get feedback from you lot about the code i produced for the loop the loop exercise.

Although I got the green go ahead button I've noticed my code was different from others and just wanted a little feedback on how I could improve?


// Our Person constructor
function Person(name, age) {
    this.name = name;
    this.age = age;

// Now we can make an array of people
var family = [];

var family1 = new Person ("alice", 40);
var family2 = new Person ("bob", 42);
var family3 = new Person ("michelle", 8);
var family4 = new Person ("timmy", 6);

// loop through our new array
for (var i = 0; i < family.length ; family++ ) {


This code is pretty much perfect, I personally wouldn't change it.



You should use indexing ..

like If I had to make an Array from scratch(of numbers)

var numbers = [];

numbers[0] = 1; 
numbers[1] = 2;

and so on..

You must have noticed that I used Bracket notation to make this numbers Array.

another thing..

for (var i = 0; i < family.length ; family++ ) family++ ?
Your iteration variable is i ?


Thanks very much guys, I know you two ( @oscartbeamish & @greentreemee ) are always on it. Ok cool. I'll brush up on indexing and read up more. That threw me slightly because I've seen others have used indexing for their arrays but when I tried i was getting error signs :


You can read this..


@greentreemee is right indexing would be better practice, but not necessary for this exercise.

But I definitely agree with this.


got it open right now, cheers for sharing the knowledge!


Ahh silly mistake, I understand you, thanks again @oscartbeamish


All good I think I can speak for @greentreemee and myself when saying we love to help


If it did not sorted out...

There you don't need var before family[0], family[1] etc!


Awesome, feel like I'm learning a good deal from you guys. Thanks again! Code is running perfectly now @greentreemee @oscartbeamish :raised_hands:


Keep up the good work! :thumbsup:


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