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

My code does not print out anything until i click cancel or type "quit"

var userInput; var flag = false;

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

do { userInput = prompt('Enter the name of the student you are interested in. (To close this app enter \'quit\')');

if (userInput === null || userInput.toLowerCase() === 'quit') { flag = true; console.log('User typed quit'); } else { students.forEach((e)=>{ if(e.name.toLowerCase() === userInput.toLowerCase()){ print(displayStudentInfo(e)); } }); }

} while (!flag)

function displayStudentInfo (obj) { var list; var listItem =''; for (var prop in obj) { listItem += <li>${prop}: ${obj[prop]}; } list = <ol>${listItem}</ol>; return list; }

2 Answers

there's a teacher's note under the video explaining why you get different behavior than is shown in the video.

thanks james, i didn't notice the teacher's note. Is there anyway to go around this tho?

the note pertains to using document.write in a loop, but there are other ways to use js to change the dom and what appears on a page, so while i'm not an expert off the top of my head, i would expect there are other way to do most whatever you want.