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
Eduardo Andre De Backer Diaz
11,472 PointsExtended solution solved! If do you have any advice to improve the code please feel free to reply! Thx
This is my solution to the extended challenge, is working good but If do you know a more efficient way to solve it feel free too reply and explain why.. :)
var message = ''; var student; var search; var found = [];
function print(message) { var outputDiv = document.getElementById('output'); outputDiv.innerHTML = message; }
function getStudentReport( student ) {
var report = '<h2>Student: ' + 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 ) { search = prompt("Search student records: type a name [Jody] (or type 'quit' to end."); search = search.toLowerCase();
if ( search === 'quit' || search === null) {
break;
}
for ( var i = 0; i < students.length; i++ ) {
student = students[i];
if ( student.name.toLowerCase() === search ) {
found.push( student );
}
}
if ( found.length > 0 ) {
for ( var i = 0; i < found.length; i++ ) {
message += getStudentReport( found[i] );
print( message );
}
} else {
alert("The student doesn't exist, press 'OK' and try again");
}
message = ""; found = [];
}