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

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

Yen Ho
seal-mask
.a{fill-rule:evenodd;}techdegree
Yen Ho
Full Stack JavaScript Techdegree Student 4,708 Points

could not print each of the student's name out

var message = ''; var student;

function print( message ) { var outputDiv = document.getElementById("output"); outputDiv.innerHTML = message;

for (var i = 0; i < students.length; i +=1) { student = students[i]; message += "<h2>Student: " + student.name + "</h2>"; } print(message); }

2 Answers

Amber Lim
Amber Lim
4,707 Points

Hi Yen Ho. I hope my answer still helps despite it being 3 months ago since you asked this question.

It's just some "grammatical" code errors. Check out the comments (in green) I left on your code.

var message = ''; 
var student;

function print( message ) {
var outputDiv = document.getElementById("output");
outputDiv.innerHTML = message; //you missed out a closing curly brace here!

for (var i = 0; i < students.length; i +=1) {
student = students[i];
message += "<h2>Student: " + student.name + "</h2>";
}

print(message); }//there should be no curly brace here

You could use the chrome developers tool to "debug" your code next time. It will show you the exact line where the problem is. Good luck.

Tatiana Vasilevskaya
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tatiana Vasilevskaya
Python Web Development Techdegree Graduate 28,600 Points

Could you please use Markdown formatting for your code? Now it is hard to read and it seems that a bunch of code is missing. For example where is the students array? Also it is worth checking where the print function ends.