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

How can I fix this problem in my code?

I did my own version of the challenge. The problem that I have is that the info doesn't appear until I type quit. Why is this happening?

var students = [ 
  { 
   name: 'Dave',
    track: 'Front End Development',
    achievements: 158,
    points: 14730
  },
  {
    name: 'Jody',
    track: 'iOS Development with Swift',
    achievements: '175',
    points: '16375'
  },
  {
    name: 'Jordan',
    track: 'PHP Development',
    achievements: '55',
    points: '2025'
  },
  {
    name: 'John',
    track: 'Learn WordPress',
    achievements: '40',
    points: '1950'
  },
  {
    name: 'Trish',
    track: 'Rails Development',
    achievements: '5',
    points: '350'
  }
];


var a = 0;
var i = 0;
search = '';

while (search !== 'quit') {
search = prompt('which student are you looking for?');    

  for (i = 0; i < students.length; i+=1) {  

    if (search === students[i].name) {

      document.write('<h2>' + 'Student: ' + students[i].name + '</h2>');
      document.write('<p>' + students[i].track + '<p>')    
      document.write('<p>' + students[i].achievements + '<p>')    
      document.write('<p>' + students[i].points + '<p>')    

        }       
        }
  }

2 Answers

Nicholas Vogel
Nicholas Vogel
12,318 Points

I should've read your question more carefully. Here's what Treehouse says about the issue you're having:

"Important Update: Since this video was shot, the behavior of most browsers has changed, so you won't see the same thing as I demonstrate in the video. In the video, you'll see that my script is able to print out to the browser using document.write( ) while inside a loop.

Most browsers no longer do that: they wait until the loop finishes and then they print to the window. So, you'll see a blank page until you type quit in the prompt window — then you'll see all the output printed to the screen."

Hope that helps!

ZoDo .
ZoDo .
13,135 Points

Thank you, I was getting crazy

Nicholas Vogel
Nicholas Vogel
12,318 Points

Is part of this code missing? I don't see an array named 'students' that the loop can go through.

just added