Sum of properties of objects from array


I have this script. It work with console.log but if I replace console.log with document.write the browser is white, don't work. Why?

function Person (name, age) { = 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);
// add the last family member, "timmy", who is 6 years old
family[3]= new Person("timmy", 6);
for(i=0; i<=family.length;i++)
{console.log (family[i]);
var sum=function(){
    var a=0;
    for (i=0;i<family.length;i++){
        return a;


inside of the codecemy lessons? the preview window in the exercise is console, not a html document


I start with the lesson from codec site but I try more for each script. I make some js file and html file to view the content of js file in a browser. Inside js file I use document.write. So, why is not working like console.log, this is my question.


because console.log() logs to the console (a tool which browsers have, often used for debugging and used in the codecademy lessons) while document.write() writes to a html document


The problem is: document.write is NOT WORKING in html document in this script!!!
Sorry for my english, I know is not too good


i put yoru code in a bin, and both work fine? press the run js button to run the JS code, both the console and document show output


Don't matters, is done. ; missing in my js file. THANK YOU