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

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);