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!
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

Brad Horvath
3,845 PointsNeed help with student record search challenge in JS
var students = [
{
name: "Bill",
track: "iOS",
achievements: 148,
points: 15667
},
{
name: "Amanda",
track: "Web Design",
achievements: 92,
points: 10464
},
{
name: "Greg",
track: "Front End Development",
achievements: 56,
points: 7584
},
{
name: "Tommy",
track: "Web Design",
achievements: 48,
points: 4473
},
{
name: "Mark",
track: "iOS",
achievements: 83 ,
points: 8573
}
];
var message = '';
var student;
var search;
function print(message) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
function getStudentReport (student) {
var report = '<h2>Student: ' + student.name + '</h2>';
report += '<p>Track: ' + student.track + '</p>';
report += '<p>Points: ' + student.points + '</p>';
report += '<p>Achievements: ' + student.achievements + '</p>';
return report;
}
while (true) {
search = prompt('Search student records: type a name [Jody] (or type "quit" to end)');
if (search === null || search.toLowerCase() === "quit") {
break;
}
for (var i = 0; i < students.length; i += 1) {
student = students[i];
if ( student.name.toLowerCase === search.toLowerCase ) {
message = getStudentReport( student);
print(message);
}
}
}
My code isn't working for some reason. It generates the last object of the array for some reason even when the name doesn't match the name searched in the prompt. Does anyone see any problems that might be causing this?
1 Answer

Iain Simmons
Treehouse Moderator 32,303 PointstoLowerCase
is a string function (or method), so you need to call it by putting an empty set of parentheses after it.
Actually, it seems you've done that the first time you used it, but not the other two.