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!

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

Same result not sure if what i did is anything like bad practice or something else?

I've got the same results but just wanted to ask if the solution i found is correct and things i did aren't considered bad practice?

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

1 Answer

I'm not sure what you mean by same results. Every time you call print you reassign the innerHTML of the output div. Since you loop through all students calling print for each property you will only display the achievements of the last student.

My bad i didn't show my print function: function print(message) { var outputDiv = document.getElementById('output'); outputDiv.innerHTML += message; }

And if im not wrong it adds to the value so in the end result is the same;