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
Max Toth
3,777 PointsMy solution to the challenge
Is here. Because of the browser issue which causes the message to print only after the user enters "quit", it displays the responses in order of user entry. How does this look?
var search = ''; var position = -1; var message = ''; var student;
function print(message) { var outputDiv = document.getElementById('output'); outputDiv.innerHTML = message; }
while(true){
search = prompt("Search for a student. Type 'quit' to exit");
console.log(search);
console.log('initial position: '+position);
if ( search === 'quit'){
break;
} else {
position = -1;
for (var i = 0; i < students.length; i += 1) {
student = students[i];
if(student.name === search){
position = i;
console.log('position within loop: '+position);
message += '<h2>Student: ' + student.name + '</h2>';
message += '<p>Track: ' + student.track + '</p>';
message += '<p>Points: ' + student.points + '</p>';
message += '<p>Achievements: ' + student.achievements + '</p>';
}
}
console.log('position before final if: '+position);
if (position < 0 ){
message += '<h2>Student '+search+' not found.</h2>';
}
print(message);
}
}