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
Ashton Rose
1,579 PointsAny reason not to do my code like this? It has the same end result as the code shown in the video.
var name;
var track;
var achievements;
var points;
for (var i = 0; i < students.length; i += 1) {
document.write("<h2>Student: " + students[i].name + "</h2>");
document.write("<p>Track: " + students[i].track + "</p>");
document.write("<p>Achievements: " + students[i].achievements + "</p>");
document.write("<p>Points: " + students[i].points + "</p>");
};
2 Answers
Steven Parker
243,656 PointsThe bigger a program is, the more ways there are to accomplish the same thing.
Your code seems efficient and is easy to read. Without seeing the original, I can only guess this likely just as good as what is shown in the video.
If you leave a link to the course page I'll take another look.
Bryan Michael Llagas
30 PointsIt's fine but it's considered bad practice by many programmers, as it only works while the page is loading. If you call it after the page is done loading, it will overwrite the whole page. Also impossible to manipulate, We cannot go back to manipulate it without tapping into the DOM.
Steven Parker
243,656 PointsUse of document.write is in many of the video examples in the beginner courses. I'd guess that part is the same as the video until I see it.
Ross King
20,704 PointsRoss King
20,704 PointsHi Ashton,
Can you provide a link to the video. I can't give you an answer without reference. However there is nothing wrong with your loop.