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

view not updated in real-time

My code works other than the fact that the view isn't updated in real time, after I submit the name of a student that exists in the 'students' array. Any help is appreciated in figuring out why that is.

js/student_report.js

var message = ''
var keepGoing = true

function print(message) {
  var outputDiv = document.getElementById('output');
  outputDiv.innerHTML = message;
}

do {
  userInput = prompt("Type in the name of a student to look up records for. Type quit to quit.").toLowerCase()

  if (userInput === null || userInput === "quit") {
    message += '<h2> You\'ve quit the program. Good day!'
    print(message)
    keepGoing = false
  } else {
      for (var s in students) {
        if ( userInput === students[s].name.toLowerCase() ) {
          message += '<h2>Student: ' + students[s].name + '</h2>';
          message += '<p>Track: ' + students[s].track + '</p>';
          message += '<p>Points: ' + students[s].points + '</p>';
          message += '<p>Achievements: ' + students[s].achievements + '</p>';
          console.log(message)
          print(message)
        }
      }
    }
 } while (keepGoing)

Is it simply because you are using Chrome instead of Firefox? They just parse the JS in a different manner. In the videos Dave McFarland is using FF, FYI.

Manav Misra , I am using Chrome. Thanks for the feedback.

1 Answer

Steven Parker
Steven Parker
231,007 Points

The main reason is that this code executes as part of the document load phase, so the browser does not consider the document fully loaded until the loop ends.

Now it could be that only some browsers withhold the display until loading is complete, but it's clearly something that cannot be counted on.

Later projects and courses will demonstrate other ways of creating interactive functionality that works after document loading, and those techniques will be immediately responsive.

Thanks Steven, this makes sense. I'm looking forward to learning how to create interactive elements post document loading.

Thanks Steven Parker!
I was having this problem in Chrome, couldn't figure it out, & it was killing me! I was going over my code for hours trying to figure it out! I was console logging everything & the correct values were displaying in the console, but would never render in the HTML. Finally opened in Firefox like Manav Misra suggested & realized it was just the way Chrome was processing my script.