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

Buggy, but found way to get multiple entries for students to display... Assistance is appreciated

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

function getRecords(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("Please enter the name of the student whose records you would like to access. To exit type 'quit'"); if( search === null || search.toLowerCase() === "quit"){ break; } for (var i = 0; i < students.length; i += 1){ student = students[i]; if(search.toLowerCase() === student.name.toLowerCase()){ message += getRecords(student); } } print(message); }

I got issues when entering new students.. the students list would continue to grow cuz of the "message+="... how can I then evaluate the new expression and print without having it display the prior students information

2 Answers

I'm not sure I understand what you questions is but if it is: "I want to display 1 student's information instead of it including all the prior students' information."

Then the solution would just be removing the + from that message +=.

message = getRecords(student);

If this wasn't the correct answer, would it be possible to define your problem a bit more?

Hi Ben,

I should have been more clear. I like the "message +=" as it resolves multiple students having the same name issue. I just feel that if I request a new students information, the prior students name would go away.

====================

1st Prompt: "Jody"

[Jody 1's data] [Jody 2's data]

2nd Prompt: "Trish" (should show the following)

[Trish's data]

====================

I am just not sure how to get started with this.