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

Ellis Beale
Ellis Beale
2,664 Points

Page doesn't render until after 'quit'

I can't seem to get it to the point of displaying one student's data AND asking for another. I found window.requestAnimationFrame(), here commented out, but that drops me out of the while loop entirely. Without it the program collects names and displays all of them at once after a quit.

var message = "";
var student;
var input;

function print(x) {
  var outputDiv = document.getElementById('output');
  outputDiv.innerHTML = x;
}
function searchStudents(name) {
  for ( i=0; i<students.length; i++ ) {
    student = students[i];
    if (input == student.name) {
      statBlock(student);
    }
  }
}
function statBlock(result) {
  message += "<h2>Student: " + result.name + "</h2>";
  message += "<p>Track: " + result.track + "</p>";
  message += "<p>Points: " + result.points + "</p>";
  message += "<p>Achievements: " + result.achievements + "</p>";
  print(message);
  //window.requestAnimationFrame();
}

do {
  input = prompt("Please enter a student's name (case sensitive), or 'quit' to stop searching.");
  searchStudents(input);
} while (input != "quit");
Peter May
Peter May
16,375 Points

I know this question is super old but i'll still answer it. In one of the updates web browsers no longer function with the command prompt like they used to. Now it prints everything after the "program" quits running. It's a little annoying.