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 trialKarol Gutkowski
8,662 PointsSame 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
KRIS NIKOLAISEN
54,971 PointsI'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.
Karol Gutkowski
8,662 PointsKarol Gutkowski
8,662 PointsMy 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;