Jennifer NordellTreehouse Staff
Hi there, Angelo! Yes, you were missing your
document.write() to print out the list of students, but there are two more problems here. The reason you were getting that
name is not defined is that on your last iteration of the loop, you were trying to access an index outside of the array.
(var i = 0; i <= students.length; i+=1 )
But you meant to write:
(var i = 0; i < students.length; i+=1 )
< instead of
students.length. If 5 students are in the array it will have a length of 5. But you are accessing the array starting at an index of 0. This means that the 5th student will be at an index of 4. On the very last iteration, you were trying to access the index of 5, which doesn't exist.
Secondly, your code will only ever print out the last student (if you added the document.write()). In the line where you add the
<h2> element, you are not concatenating onto the
message string, but overwriting it completely. Here, you simply missed a + sign.
message = "<h2>" + students[i].name + "</h2>";
But that should be:
message += "<h2>" + students[i].name + "</h2>";
Hope this helps!