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 Student Record Search Challenge Solution

Gaia Dragonfly
Gaia Dragonfly
4,546 Points

The extra credit challenge: a weird problem.

A snapshot of my project: https://w.trhou.se/7r370agax8

I changed quite a lot of stuff in it, and used a function to add student objects into the array, which changed some of the code accordingly.

I managed the improvements he talks about at the end of the video, but for some reason when I run the code it always prints 'undefined' before printing the student's report. (to see it run the code and enter 'uri' in the dialogue box)

It's driving me a bit crazy trying to fix it... any ideas?

1 Answer

Jason Desiderio
Jason Desiderio
21,811 Points

Gaia Dragonfly - Since you are the "+=" to add more to your var details and var message strings, you have to declare them as an empty string using var details = ""; and var message = ""; else it will spit out undefined.

Change your code to these and it will work as expected:

/*******************
      VARIABLES
*******************/

var students = [];
var message = "";
var student;
var search;
var notListed = true;
function studentDetail (place) {
  var details = "";
  details += "<h2>Student's Report:</h2>";
  for (var prop in students[place]) {     
     details += '<p>'+ prop + ' : ' + students[place][prop] +'</p>';
  }
  return details;
}
Gaia Dragonfly
Gaia Dragonfly
4,546 Points

It always seems so obvious when someone else tells you :)