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

My solution

3 Answers

James Estrada
James Estrada
Full Stack JavaScript Techdegree Student 25,862 Points

Nice solution!! You solved both problems the teacher left unsolved :)

I would add a suggestion to your code in one section of your while loop so it prints both found and not found students:

  noMatch = true;
  for (let i = 0; i < students.length; i++) {
    if (student === students[i].name.toLowerCase()) {
      noMatch = false;
      records += `<p><strong>Name: ${students[i].name}</strong></p> <br>`;
      records += `<p>Track: ${students[i].track}</p> <br>`;
      records += `<p>Achievements: ${students[i].achievements}</p> <br>`;
      records += `<p>Points: ${students[i].points}</p> <br>`;
      //print(records); // print them at the end of your while loop
  if (noMatch) {
    notFoundStudent = `The student ${student} is not found`; // you can add <p> tags to separate all not found students
    records += notFoundStudent; // adding this to your records variable will allow you to see a list of who was and wasn't found
    //print(notFoundStudent); // having both print statements in the case a student was found or not will cause an overwrite. Try searching for a match and no match with your original code to see what I mean
  print(records); //this will print both found and not found students 
Steven Parker
Steven Parker
217,626 Points

Good job! And good use of the snapshot. :+1:

Two minor suggestions, when you need to use the same index of an array several times you can create a temporary variable to refer to that item directly. And paragraphs automatically add vertical space, so explicit <br> isn't needed:

      let s = students[i];  // simplify the remaining references
      records += `<p><strong>Name: ${s.name}</strong></p>`;
      records += `<p>Track: ${s.track}</p>`;
      records += `<p>Achievements: ${s.achievements}</p>`;
      records += `<p>Points: ${s.points}</p>`;

Thanks for your recommendation! I will take it into account :)