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 trial3 Answers
James Estrada
Full Stack JavaScript Techdegree Student 25,866 PointsNice 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
console.log(records);
}
}
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
console.log(notFoundStudent);
//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
231,275 PointsGood job! And good use of the snapshot.
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>`;
Alina Bylkova
6,862 PointsThanks for your recommendation! I will take it into account :)