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

can somebody please help me with displaying all records of students with the same name?

The Student Record Search Challenge Solution https://w.trhou.se/nw42o565t2

1 Answer

for(var i = 0; i < students.length; i += 1) {
    student = students[i];
    if(search.toLowerCase() === student.name.toLowerCase()){
      message = studentRecords(student);
      found = true;
    } 

Try changing

      message = studentRecords(student);

to

      message += studentRecords(student);

Setting message = studentRecords(student) is causing message to be deleted and rewritten every time there is a match meaning only the record for last student in the array with the same name will be shown. Writing message += studentRecords(student) causes the message to be added to whenever a duplicate name is found which will return the records for every student with that same name.

Thanks a bunch Justin! Loved the way you broke it down.