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

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