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 trialn0 mad
2,107 PointsChallenge - Student records - Final Step - stuck
Hey guys,
I've messed something up in the challenge, which took me a bit longer than I've expected... but it was a cool refresher of all the stuff covered earlier on.
Here's the issue: I only see the records after closing the prompt window
Here's the code:
var message = " "; var searchInput = " ";
function print(message) { var outputDiv = document.getElementById("output"); outputDiv.innerHTML = message; }
function studentReport(student) { var report = '<h2>' + 'Student: ' + students[i].name + '</h2>'; report += '<p>' + 'Track: ' + students[i].track + '</p>'; report += '<p>' + 'Achievements: ' + students[i].achievements + '</p>'; report += '<p>' + 'Points: ' + students[i].points + '</p>'; return report; }
while (true) { searchInput = prompt("Enter the name of the student you want to stalk"); if (searchInput.toLowerCase() === "quit" || searchInput === null) { break; } for(var i = 0; i < students.length; i++) { student = students[i] if (student.name === searchInput) { message = studentReport(searchInput); print(message); } } }
Frankly I just want to move on, tried to figure out what I've messed up but it's taking too long, seriously. If you can take a look and let me know, that would be awesome.
1 Answer
Gabbie Metheny
33,778 PointsIf you're seeing the records when you close the prompt window, I think you're experiencing the problem Dave mentions in 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.
If that isn't what you're experiencing, I'm happy to take a look at your code if you format it with the Markdown Cheatsheet or take a snapshot of your workspace! Let me know!