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

Aaron Loften
Aaron Loften
12,864 Points

Not seeing dynamic results in student records challenge after entering a new name...

Using the "workspaces" provided by treehouse. Windows 10, chrome, 8gb ram and running smoothly on all programs during this glitch.

Problem: Following the steps in the video, I never saw the page update, until cancel was pressed or prompt was exited with break text.

I kinda wasted two hours trying to wonder why I only got the correct element updated with the proper information upon exiting the prompt.

I say wasted because this was not an issue at all. I had about four-five ways completely written out, and eventually gave in and copy and pasted from the teachers downloads.

I still had the same result when running the script.

I just wanted to post this somewhere, incase someone else had the same issue.

How do you know if your script is correct then? If no error is received in console, consider looking at the elements in dev tools it will update as you do this, but there will be no visual note of this on the screen until you close the prompt. This should be noted somewhere.

Im assuming this is more of a state checking issue where the while statement is continuously checking for the prompt result, preventing any display updates on the page.

Idk, could just be a me issue. I think its worth noting. Sorry for posting it here. I saw no place to post this.

Teacher-provided script below...(requested by commenter)

var message = '';
var student;
var search;

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

function getStudentReport( student ) {
  var report = '<h2>Student: ' + student.name + '</h2>';
  report += '<p>Track: ' + student.track + '</p>';
  report += '<p>Points: ' + student.points + '</p>';
  report += '<p>Achievements: ' + student.achievements + '</p>';
  return report;
}

while (true) {
  search = prompt('Search student records: type a name [Jody] (or type "quit" to end)');
  if (search === null || search.toLowerCase() === 'quit') {
    break;
  }
  for (var i = 0; i < students.length; i += 1) {
    student = students[i];
    if ( student.name === search ) {
      message = getStudentReport( student );
      print(message);
    }
  }
}

Could you post your code?

3 Answers

Hey guys,

So the problem is really that the Challenge is a contrived example; it has no clearly defined purpose. As you noticed, you won't see the HTML update until the while-loop stops calling prompt(). This isn't wrong, per se, because right-vs-wrong would depend on what your goals were. For example, if your print() function was appending every consecutive, successful search result to the HTML then it might make sense to let the user just keep typing names in until they were done and typed 'quit.' But, again, that's also a contrived example. Honestly, the key takeaway from this Challenge is pedagogical in nature: JavaScript objects can be stored as an ordered list inside of JavaScript Arrays and then you can loop through each member of that list and do whatever you want to the contents.

So, yeah, try not to get too hung up on the ambiguity here; just move on — it'll all eventually make sense.

Aaron Loften
Aaron Loften
12,864 Points

I agree, however, the main point of throwing this up for other users, is when this happens, a user sees a constantly loading symbol, in chrome, as if the page is not finished(where you would normally see a refresh button).

I fully understood this, but I thought I was stuck in a loop. I attempted to exit the loop upon a correct answer, then jump back into the loop after updating the dom. This did not work, nor did delays.

I think you're right about the point in the lesson versus the usefulness of the actual program made, in a real world situation. But as a developer wanting to fine-tune these skills, the end-result should match the teacher's for me to consider my understanding complete.

I think it would be neat to update this lesson with an input box and submit button, instead of a prompt. It would be more code, but more likely to be cross-user compatible(and can be mostly set up before the student opens the workspace, preventing much extra coding on the student's behalf). Heck, it could be in inverse of the current and even display an alert, based on a search result. <- way less useful in real-life, but 'should' show similar results, from one screen to the next.

Still a good lesson. Just wish the browser responded the same.

Just want to mention that in Mozilla the program works as expected. I also spent hours, even slept over it until I figured out it could just be browser dependent.

Chris Underwood
seal-mask
.a{fill-rule:evenodd;}techdegree
Chris Underwood
Full Stack JavaScript Techdegree Student 19,916 Points

I just had the same exact problem on my machine but copying the text into Atom instead of workspaces. I am running on Mac using Chrome v 53. Glad to see I am not suffering alone at least.

Aaron Loften
Aaron Loften
12,864 Points

Probably a good idea moving forward for debugging. I like workspaces, but if it does 'trip-up,' debugging in it is not the best idea.

Christopher Collins
seal-mask
.a{fill-rule:evenodd;}techdegree
Christopher Collins
Front End Web Development Techdegree Student 6,343 Points

Not an Answer I just wanted to send a thanks Aaron Loften . I was having this same problem and typically I do the exact same thing as you. Rather than heading into the teachers code, I will spend HOURS trying to think through to the solution my-self (I consider this good learning practice) and only resort to the "answer book" when absolutely required. This time however, I was going through with the video an knew for a fact the code didn't have any errors and by checking in and reading your comment and the mod's reply I saved at least have a day or running in circles for no good reason.. TL;DR - Thanks for posting this, you saved me a ton of time on an issue that really is a 'non-issue'.

Aaron Loften
Aaron Loften
12,864 Points

Anytime, friend! :D I did the same thing. several....several hours before realizing it wasnt me.