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

Can't get results to print in Chrome.

What am I missing here? I keep comparing my code to his in the video and not seeing a difference. Java console also detects no errors.

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

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

function getStudentReport(student) {
  //declaring variable that only lives inside function
   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 for a student by name. Type a name to see student records or type 'quit' to exit.");
  //if search is null or = quit, exits loop
  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);
    }

   }
}

2 Answers

LaVaughn Haynes
LaVaughn Haynes
12,397 Points

Try typing Dave with an uppercase D at the prompt and see if that works. If it does the the reason your code doesn't print is because the name you entered and the students names are different cases, so the line below returns false and doesn't execute the print code

if (student.name===search) {

You can make them both the same case, or be sure to enter the name at the prompt with an uppercase first letter

 if (student.name.toLowerCase() === search.toLowerCase()) {

Thanks -- that was it! I was typing the names in lower case.

JavaScript* console

Do you have a div with an id of output?