Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.