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

tomd
tomd
16,701 Points

Copied code exactly and it doesn't work..

So I cant complete a single challenge on my own. Now I copy everything exactly and it doesn't work. I really don't understand whats going on..

var search;
var message = '';
var student;

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

function getStudentReport(student) {
    var report = '<h2>Student: ' + student.name + '</h2>';
    report += '<p>Track: ' + student.track + '</p>';
    report += '<p>Points: ' + student.points + '</p>';
    report += '<p>Achievements: ' + student.achievements + '</p>'; 
  return report;
}

  while (true) {
  search = prompt("Search student records: type a name [Dave](or type 'quit' to end)");
  if (search === null || search.toLowerCase() === 'quit') {
    break;
  }
   for (var i = 0; i < students.length; i += 1) {
    student = students[i];
    if (student.name === search) {
      message = getStudentReport(student);
      print(message);
    }    
  } 
}

thanks

4 Answers

Tom, if you're having the same problem I did, also after not having the code print out. I type the code in exactly like how it was in the video, but it wouldn't print out the student records. So, I figured out the problem it was in my students.js file, the names in the name field had the first letter capitalized, I changed to lower case and after that it worked.

Thank you Gremyko, I was having the same problem and could not for the life of me figure it out!

The teacher's notes of the video say:

Since this video was shot, the behavior of most browsers has changed, so you won't see the same thing as >I demonstrate in the video. In the video, you'll see that my script is able to print out to the browser using document.write( ) while inside a loop.

Most browsers no longer do that: they wait until the loop finishes and then they print to the window. So, you'll see a blank page until you type quit in the prompt window — then you'll see all the output printed to the screen.

So if the alert is what is not working, that is why.

Tyler Durden
Tyler Durden
2,406 Points

Holy fuck, that god. I had the my data printing out, but spent fucking 30min-1hour trying to figure out why the hell it was only printing AFTER i hit QUIT (sorry for profanities but super frustrated).

You guys need to do an update on the video ASAP before people paying for this program waste 1 hour of their lives like I just did -_-

Milad Latif
Milad Latif
6,189 Points

Thanks Gremyko! I did what you said and it finally worked.

This one was frustrating but learnt a lot!

Mihail Petkov
Mihail Petkov
8,892 Points

Hello, Tom,

Which part of this code does not work correctly ?