So I am following a javascript course on codecademy, I decided to try things out on my own script. So the script is:
function family1 (name, age) {
this.name = name;
this.age = age;
}
var family = new Array();
family[0] = new family1("alice", 40);
family[1] = new family1("bob", 42);
family[2] = new family1("michelle", 8);
family[3] = new family1("timmy", 8);
printFamily1 = function(person) {
console.log(person.name + " aged " + person.age);
}
console.log(printFamily1(family[0]))
console.log(printFamily1(family[1]))
console.log(printFamily1(family[2]))
console.log(printFamily1(family[3]))
It works, but in the console, it printed
alice aged 40
undefined
bob aged 42
undefined
michelle aged 8
undefined
timmy aged 8
undefined
It works, but I don't want the undefined part! How do I fix these!