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
Susheel KB Kaparaboyna
1,005 PointsMy code is working without any break statement for the problem of repeated student names
var message = ''; var student;
function print(message) { var outputDiv = document.getElementById('output'); outputDiv.innerHTML = message; }
var student_name= prompt('who do you want to search for?');
for (var i = 0; i < students.length; i += 1){ var student= students[i]; if(student_name==student.name){ message += '<h2>Student: ' + student.name + '</h2>'; message += '<p>Track: ' + student.track + '</p>'; message += '<p>Points: ' + student.points + '</p>'; message += '<p>Achievements: ' + student.achievements + '</p>'; }
} /*for (var i = 0; i < students.length; i += 1) { student = students[i];
}*/ print(message);
Steven Sullivan
11,616 PointsI agree with Steven Parker. Your students array:
var student= students[i];
Doesn't appear to have any data. It has the value of [i], which in your loop continuously counts.
You have not defined a length, so it continues.
Steven Parker
243,656 PointsSteven Parker
243,656 PointsI don't quite understand your issue, could you rephrase the question?
This code looks like it might work if it had some data in a "students" array.