Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Student Record Search Challenge Solution

Brandon Wong
Brandon Wong
2,341 Points

Student records are not appearing

What did I do wrong?

Student records are not appearing when I search by name using this code.

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

function print(message) { 
  var div = document.getElementById("output");
  div.innerHTML = message; 
} 

function getStudentScore(student) { 
  var report = '<h2>Name: ' + student.Name + '</h2>'; 
  report += '<p>Track: ' + student.Track + '</p>'; 
  report += '<p>Achievements: ' + student.Achievements + '</p>'; 
  report += '<p>Points: ' + student.Points+ '</p>';
  return report;
} 


while (true) {
  search = prompt("Search for a student by name. To exit, type 'quit.'"); 
  if (search === null || search.toLowerCase() === 'quit') { 
  break;
  }
    for (var i = 0; i < students.length; i += 1) {
      student = students
      if (search === student.name) { 
      message = getStudentScore(student);  
      print(message);
      }
     } 
} 

2 Answers

You have two issues:

1) In your for loop you assign student the entire array

student = students;

should be

student = students[i];

2) In your getStudentScore() function the student properties should be lowercase instead of title case. For example

student.Name

should be:

student.name