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

innerHTML doesn't render until I quit. The prompt seems to interfere with the browsers ability to render.

I am attempting to loop as the program states. After I enter in the 1st student it doesn't render and just continues to ask for the next student until I quit. Once I quit, it renders the most recent student's information. Based on my research I saw that the prompt function maybe interfering with the browsers ability to render. Also, I saw a note about browsers being different today than what they were when this video was created. Is there a solution to this?

1 Answer

Diane Leigh
Diane Leigh
16,813 Points

I found this answer on stack overflow: https://stackoverflow.com/questions/45669952/take-color-as-input-and-change-the-background-and-foreground-color-repeatedly-ti/45670253#45670253

Here is how I implemented it: instead of the While loop I created a function. Not sure if it is the best way but it worked!

function callback() { search = prompt("Please enter the name of a student to search for or type 'quit' to exit"); if (search === null || search.toLowerCase() === 'quit') { cancelAnimationFrame(globalID); } for (var i = 0; i < students.length; i += 1) { student = students[i]; if ( student.name === search) { message = getStudentReport(student); print(message); globalID = window.requestAnimationFrame(callback) } } } window.requestAnimationFrame(callback);