Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Build an Object Challenge, Part 2 Solution

If you add an object to students is the students.js updated?

Hi I just did an experiment and added one more student to the array.

Please see below:

var message = ''; var student; var new0bject = { name: 'Alina', track: 'front-end', points: 1000 };

function print(message) { var outputDiv = document.getElementById('output'); outputDiv.innerHTML = message; }

function pushObject(object) { students.push(object); }

pushObject(new0bject); console.log(students);

for( var i = 0; i < students.length; i += 1 ) { student = students[i]; message += '<h2>Student: '+ student.name + '</h2>'; message += '<p>Track: '+ student.track + '</p>'; message += '<p>Points: '+ student.points + '</p>'; }

console.log('hi'); print(message);

The new student was printed and also shown in the console when I logged the new students.

However, when I checked the sources the students.js was not updated with the new object.

My question is if I use .json would I see in the file the new object? Not sure how these files are updating or saving information.

Thank you, Alina

Raymon Oleaga
Raymon Oleaga
19,298 Points

No, you will not add a new student or data into a local json file by doing this. You will need a database or api to do that. What you are doing is simply adding this new user to the DOM but that does not save it into a file.