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 trialTammi Carter
5,360 PointsPlease help? When attempting to search the students records only appear once I hit cancel , quit isn't working??
var message = '';
var student;
var search;
function print(message) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
function getreports(students){
var report = '<h2> Name: '+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) {
message = '';
search = prompt('Enter a students name to search, once the search is complete type the word QUIT to close the prompt');
if (search === null || search.toLowerCase() === 'Quit' ){
break;
}
for (var i = 0; i < students.length; i += 1) {
student = students[i];
if (student.name.toLowerCase() === search.toLowerCase() ) {
message += getreports(student);
}
}
if(message === ''){
message = 'No records found: '+search;
}
print(message);
}
4 Answers
Steven Parker
231,172 PointsThis code is converting the input into lower case, then comparing it to "Quit" (with capital "Q"), so it's not possible for it to match.
Compare the lower-cased input with "quit" (all lower case) instead.
Tammi Carter
5,360 PointsThank you Steven!!! So why is it that I canβt get each students data to appear until after I hit cancel or clear? The Data appears for the last student name that I input and only appears after I quit or cancel
Jamie Reardon
Treehouse Project ReviewerIf you see the teachers notes there will be an update message explaining this behaviour.
Steven Parker
231,172 PointsIn case you're not on the page with those notes, the behavior of modern browsers has changed since the video and now browsers don't render the page until the JavaScript code completely finishes.
Tammi Carter
5,360 PointsThank you Jamie I will take a look
Tammi Carter
5,360 PointsOohhhhh π.... Well that at least makes my brain feel better!!! Iβm on slack but learning how to navigate all of my tools π§°. STEVEN YOU ARE AWESOME βοΈβοΈβοΈππΎ Thank you again!