JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Build an Object Challenge, Part 2 Solution

Ru Song
seal-mask
.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>';