27 Loop the Loop unexpected identifier error


#1



I keep getting an Unexpected Identifier error. I think there may be something wrong with my function. I've compared it to other posts, and most of them have similar code.


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

// Now we can make an array of people
var family = newArray();
family[0] = new Person ("alice", 40);
family[1] = new Person ("bob", 42);
family[2] = new Person ("michelle", 8);
family[3] = new Person ("timmy", 6);

// loop through our new array
for (i = 0; i < family.length; i++) {
    return family[i].name;
};


#2

Ok, first, in your for statement. Instead of doing i < family.length; I would suggest i<4. Since you are not going to go above 4 I see this is the best way to do it. Also, don't return your family[i].name but console.log it.


#3

I knew the code was right, I found what the syntax error was. The letter 'F' in Function needs to be lower case. When I did this, the words name and age turned orange instead of white. In addition, I needed a space between new and Array, its not supposed to be one word "newArray".


#4

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