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

My solutions only prints names and doesn't print any other properties. Which are coming up as undefined.

I'm sure its a minor adjustment that is needed. However, my code currently prints only the name properly. Otherwise it prints, "Track: undefined", "Points: undefined" etc.

I'm not sure where I went wrong. I've been looking at it for far to long. Please let me know if you see something that I've done incorrectly.

//student_report.js

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>'; message += '<p>Track: ' + students.track + '</p>'; message += '<p>Points: ' + students.points + '</p>'; message += '<p>Achievements: ' + students.achievements + '</p>'; } print(message);

//index.html

<!DOCTYPE html> ... <h1>Students</h1> <div id="output">

</div> <script src="js/students.js"></script> <script src="js/student_report.js"></script> </body> </html>

// students.js

var students = [ { name: 'Dave', track: 'Front End Development', achievements: 158, points: 14730 }, { name: 'Jody', track: 'iOS Development with Swift', achievements: '175', points: '16375' }, { name: 'Jordan', track: 'PHP Development', achievements: '55', points: '2025' }, { name: 'John', track: 'Learn WordPress', achievements: '40', points: '1950' }, { name: 'Trish', track: 'Rails Development', achievements: '5', points: '350' } ];

1 Answer

Seth Shober
Seth Shober
30,240 Points

Hi seattler,

Since, the name property is only thing that works I analyzed that first and then compared to the other properties to look for differences. The first thing I saw is that you are using student.name, and in the others you are using students (with an s).

I see you are defining student here: student = students[i];

I imagine this is your preference for readability and can see how easy it would be to forget the 's'. If you update your other property references to use student instead of students I think you will have success.

Cheers!

I knew it was going to be a small thing. Thank you!

Seth Shober
Seth Shober
30,240 Points

I'm glad to help!