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 trialSaqib Ishfaq
13,912 Pointsonly one student name prints for me, one i type in the end. even though the code exactly the same!
var student;
var search;
var message = '';
function print(message) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
function getStudentRecord(student){
var report = '<h2>student: ' +student.name+ '</h2>';
report += '<p>track: '+ student.track+ '</p>';
report += '<p>achievements: ' +student.achievements+ '</p>';
report += '<p> points: ' +student.points+ '</p>';
return report;
}
while(true){
search = prompt('type a student name to search the record, and to end type \'quit');
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 = getStudentRecord(student);
print(message);
}
}
}
2 Answers
Olga DC
16,680 PointsThe print function is replacing what's inside the html div each time it is called. That's why you can only see the last student you searched for. I found changing the code inside the print function to this one solved that problem:
function print(message) {
document.write(message);
}
Matthew Long
28,407 PointsYou may be referring to the change in behavior in browsers since the recording of the video. This is explained in the teachers notes.
Saqib Ishfaq
13,912 Pointsno! only one student name is printed even when i type quit in the end(as per browser behaviour).if i want to see 2 students names together its doesn't get printed on the page