27 Loop the loop


#1

help please, console writes what it should be the right answer, but it keeps sayin` some error...

// 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();
// loop through our 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("je m'appelle "+ family[i].name +" et j'ai "+ family[i].age +" ans." );
};

Oops, try again.
** It looks like the object at index 0 was not created with the Person constructor**


#2

@stephanator13,
With

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

you create a so-called object class constructor
and by Javascript code convention
you will have to use a Capitalized Name
like Person

So modify your =person= class-constructor's name into =Person=
like

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

and modify the rest of your code to comply with this change.....


#3

tu t'ait trompé quand tu crée un objet avec le constructeur tu doit réutilisé le meme nom que c'elle de ton constructeur pour crée tes objet si ta fonction s'écrit Person () alors quand tu crée un objet tu doit reutilisé la meme orthographe en faisant famille = new Person("truk 1", truk 2)


#4

Thanks a lot for your enlightment! :smile: It works!
I will keep that Capitalized Name for object class constructor in mind, sure!


#5

Merci aussi à vous,! :slightly_smiling:


#6

@stephanator13,

### Reference
google search
== the Book ==
javascript [your question] site:developer.mozilla.org

== discussions / opinions ==
javascript [your question] site:stackoverflow.com

== guidance ==
www.crockford.com
http://javascript.crockford.com/code.html <---JavaScript code-convention
http://javascript.crockford.com/survey.html
https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript
www.developer.mozilla.org/en-US/docs/Web/JavaScript/Guide
http://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript
http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname?rq=1


#7

Interesting advice in that JavaScript code-convention's link! Thanks, Leonhard!