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 trialMick Webb
2,247 PointsCode won't work for solution: No syntax errors that I can see, code won't print to browser:
Here is my code: (students.js):
var students = [ { name: 'Mike', track: 'Front End Development', achievements: 158, points: 14370 }, { name: 'Jody', track: 'Front End Development', achievements: 158, points: '16375' }, { name: 'Jordan', track: 'PHP Development', achievements: '55', points: '2025' }, { name: 'John', track: 'Learn Wordpress', achievements: '40', points: '1950' }, { name: 'Trish', track: 'Rails Development', achievements: '5', points: '350' } ];
var message = ""; var student; var search;
function print(message){ var divOutput = document.getElementById('output'); divOutput.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)'); if (search.toLowerCase() === 'quit'){ break; } } for (var i = 0; i < students.length; i++) { student = students[i]; if (student.name === search){ message = getStudentReport( student); print(message); } } }
2 Answers
Jeff Waite
8,257 PointsYou've got a problem with your string formatting in the search prompt-- The 'quit' should be in double quotes (") or conversely, the entire string should be encapsulated with double quotes. You've also got two closing curly brackets after your break command in your first if statement in your while loop.
while (true){ search = prompt('Search student records: type a name [Jody] (or type 'quit' to end)'); if (search.toLowerCase() === 'quit'){ break; } }
Mick Webb
2,247 Pointsthe only thing that shows up is the header, and the search function does not pop up.
Jeff Waite
8,257 PointsJeff Waite
8,257 PointsI haven't reviewed your code, but did you notice the teacher's note?
He specifically mentions document.write() in this explanation, but apparently his print() function suffers from the same issue.