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 course Arrays and objects by dave

The final challenge regarding searching any array of object literals, for a student and printing them to the dom, does not work as described in the video I copied it and tested it..

The problem is the while loop only displays the student that is found after you quit the script allowing the body tag and html tag to close.. I have the code he used below is there a way around this..

var message = ''; var student; var search;

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("Type in student name to search for, or type quit to exit program" ); if (search === null || search.toLocaleLowerCase() == 'quit') { break; }

for (var i = 0; i < students.length; i += 1) { student = students[i]; if (student.name === search) { message = getStudentReport(student); print(message);

}

}

}

3 Answers

there is a teacher's note under the video explaining this behavior.

check your syntax and also your console (windows: f12 / mac: fn+ f12 on firefox). I ran your code myself and saw that i was missing a closing bracket for the while loop. Let me know if you get any errors on the console.

For future reference you can display your code in between Three Back Ticks ( ` ) on either side of your code. It will make it easier to glance at.

var yourCode = "Looks good"