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

JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Student Record Search Challenge Solution

Patrick Espiritu
PLUS
Patrick Espiritu
Courses Plus Student 4,171 Points

Not sure what I am missing but the values are not showing up when I type one of the names in the search box.

var message = ''; var student; var search;//to seach

function print(message) { var outputDiv = document.getElementById('output'); outputDiv.innerHTML = message; }

function getStudentReport (student){//var declared inside a function only exist inside a funtion var report = '<h2> Students: ' + student.name + '</h2>'; report += '<p>Track: ' + student.track + '</p>'; report += '<p>Points: ' + student.points + '</p>'; report += '<p>Achievements: ' + student.achievements + '</p>'; return report;//function must return final string into report variable }

while(true){//search prompt dialog using while loop search = prompt('Search student records: type a name [Judy] (or type "quit" to end)'); if (search === null || search.toLowerCase() === 'quit'){ break;//stops prompt } for (var i = 0; i < students.length; i += 1){//printing value from students array student = students[i]; if (student.name === search ){ message = getStudentReport(student); print(message); } } }

Maybe this happens because the script runs before the HTML is finished loading. It looks like the code works fine, but the page doesn't finish rendering until the script is done running.

1 Answer

Ezra Siton
Ezra Siton
12,644 Points

Hi first re order your code. You have a lot of code in comment mode (Add the comment to the end of the line!!) so for now, your code is like gibberish + syntax errors

wrong:

// Declare x, give it the value of 5         var x = 5;      

Fine:

var x = 5;      // Declare x, give it the value of 5
var x = 5;      /* Declare x, give it the 
value of 5 */