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

Nathalia Buitrago Jurado
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Nathalia Buitrago Jurado
Front End Web Development Techdegree Graduate 18,327 Points

I cant get this code to work.

I have checked 3 times to see what is wrong copying step by step what Dave does on the video, when i type "quit" it works, but if i type any of the students names nothing happens and it never prints the reports on the page, could you please help me to figure out what is wrong with my code ?

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>'; }

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 === search ) { message = getStudentReport( student ); print(message); } } }

Erwan EL
Erwan EL
7,669 Points

Write your code using ``` before and after your code

2 Answers

Steven Parker
Steven Parker
231,275 Points

There's no data here to test with, but one potential issue is that the code is doing a case-sensitive search.

If your search term was not an exact match for a name (including case), it would be normal for nothing to be printed.

If that's not the issue, be sure to include all the code and mention what you entered to search on. You can also make a snapshot of your workspace and post the link to it here to share everything at once.

Ken S.
Ken S.
3,838 Points

Also, make sure you actually have student objects in your students.js file... :)

And lookout for typos in your index.html. I did that and I was ready to flip tables...

It would also be easier to help if you code was easier to read. Perhaps that is what Erwan is talking about?