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

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

1 Answer

Peter May
Peter May
16,376 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.