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 Solution

Browser not displaying information like Dave's example, even after moving print(message) outside of the while loop.

When I search for the students name, nothing prints to the page, until I type quit, then only the last student in the array appears. Ive tried moving the print function in and out of the loop, and now im out of ideas. Can some one clarify?

let message ; let student; let search;

const print = message =>{ let outPutDiv = document.getElementById('output'); outPutDiv.innerHTML = message; }

const getStudentReport = student =>{ let report = "<h2> Students : " + student.name + "</h2>"; report += "<p> track : " + student.track + "</h2>"; report += "<p> track : " + student.achievements + "</h2>"; report += "<p> track : " + student.points + "</h2>"; return report;

}

while(true){ search = prompt('search student records : [loop] type "quit" to quit '); if(search.toLowerCase() === "quit" || search === null){ break; } }

for(let i = 0; i<students.length; i+=1){ student = students[i]; if(student.name.toLowerCase() === search.toLowerCase()){

}

} message = getStudentReport(student);

print(message);

Kristaps Vecvagars
Kristaps Vecvagars
6,191 Points

Same here. Initially I thought I had misplaced the print(message), however, after looking through Dave's solution, I realized I actually got the solution right on my own, and apparently the whole thing works differently on my PC/browser. I wonder, if that is true or is there something else at work here. I'm using Windows 10 and Chrome.

2 Answers

From the teacher's notes for the video:

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.

Kristaps Vecvagars
Kristaps Vecvagars
6,191 Points

That explains it, thanks! I guess it pays off to read the notes. If only I wasn't so lazy :)

Thanks for the explanation. I thought I was doing something wrong!

Daniela Fernandes Smith
Daniela Fernandes Smith
9,658 Points

Is there a way to "break" from the dialogue box as soon as you type a valid name on the prompt? So the browsers will behave like they used to, when the video was recorded? I tried including a break statement right before closing the if statement that looks for a valid search result, but it didn't do anything, oops. Thanks in advance!