27: loop the loop works but format question


#1

The code below works.
Should there be a semicolon after the function or not? Or is a constructor function holding objects not dealt with the same way as a function?
Also, how do you format code in this window. I have tried a lot of the icons already and none seem to work! <

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

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

for(i=0;i<4;i++){
console.log(family[i].name);
}`


#2

In this case there should be no semicolon after a function. if you were assigning the function to a variable then you would need one.

so if you used an assignment statement on the function such as then it would be necessary.

var Person = function (name, age) {
this.name = name;
this.age = age; 
};

semicolons are only necessary after assignment statements or if you have statements on the same line. In other case they are not obligatory.

Please see the following link for more information:
https://www.codecademy.com/forum_questions/507f6dd09266b70200000d7e

Regarding formating on the forum, surround your code with three back-ticks.. back-ticks are above the tab key on your keyboard, to the left of number 1.
`