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

Can't Find Mistake in My Copy of Dave's Code

I've tried to type Dave's solution as presented in the video, but it isn't working for me. It prompts for a name, but doesn't display anything until you type in 'quit'. Only then will it display only the info for the last student input:

//Dave's student_report.js Solution//

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

Please help me find my typo. I'm not getting any syntax errors.

Thanks.

(Sorry for the pitiful way this posted. I've seen others post code that looks like it's copied from CodePen, but I have no idea how they do that. Maybe that's another question.)

1 Answer

No errors. I think Dave explains what you are experiencing in the teacher's notes for the video which is posted below:

Important Update Since this video was shot, the behavior of most browsers has changed, so you won't see the same thing as I demonstrate in the video. In the video, you'll see that my script is able to print out to the browser using document.write( ) while inside a loop.

Most browsers no longer do that: they wait until the loop finishes and then they print to the window. So, you'll see a blank page until you type quit in the prompt window — then you'll see all the output printed to the screen.

Thanks, Kris. For some reason I thought that the print(message) function eliminated that anomaly. So much to keep up with.