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

Ru Song
.a{fill-rule:evenodd;}techdegree seal-36
Ru Song
Front End Web Development Techdegree Graduate 13,845 Points

Print issue

If I follow the video to call the print function outside for loop, there is only the last part in the array printed out. But what if I call the function inside the for loop, then all message printed out. I don't know what is wrong of my code?

for (var i = 0; i < student.length; i++) { content = '<h1>Student: ' + student[i].name + '</h1>'; content += '<p>Track: ' + student[i].track + '</p>'; content += '<p> Achievement: ' + student[i].achievement + '</p>'; content += '<p> Points: ' + student[i].points + '</p>'; print(content); }

1 Answer

See the video @ 2:40. Notice that he uses message += . For you this would be:

content += '<h1>Student: ' + student[i].name + '</h1>';