[RESOLU - SOLVED]Intro object 1 27/33 RangeError: Maximum call stack size exceeded


#1

salut je galère sur ce code depuis hier avec cette érreur : RangeError: Maximum call stack size exceeded
hi all i have a mistake in my code check the error message RangeError: Maximum call stack size exceeded

this is my code:

var Personne = function(nom, age) {
this.nom = nom;
this.age = age;
Personne.famille = new Array();
for (var i = 0; i <= 4; i++) {
Personne.famille[i] = new Personne('alice', 40),
new Personne('bob', 42),
new Personne('michelle', 8),
new Personne('timmy', 6)
console.log(Personne.famille.nom);
}
}


#2

Hi first this part

var Personne = function(nom, age) {
this.nom = nom;
this.age = age;
} <== you should close it here

Your array should be outside

2

Personne.famille = new Array();

If you want to create a new array you should do it like that

var family = new Array();

And your new Person you should create Them Like that

family[0] = new Person("alice", 40)
family[1]
family[2]
......

And for printing the name of your family you should use a for loop


#3

thanks i will try now


#4

hi dear i found the solution by myself by using grey matter :slightly_smiling: watch my code !

function Personne(nom, age) {
this.nom = nom;
this.age = age;
}
var famille = new Array();
famille[0] = new Personne('alice', 40);
famille[1] = new Personne('bob', 42);
famille[2] = new Personne('michelle', 8);
famille[3] = new Personne('timmy', 6);
for (var i = 0; i < famille.length; i++) {
console.log(famille[i].nom);
}

i was in many mistake because i was'nt really understand my function was my constructor xD after keep that in mind i was able to write the second part of the code exercice and finaly write the for loop
i hope my answer can help some other student