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

I am trying to accomplish the extra challenges that has been told in the video. Can anyone fix the problem in my code.

I am trying to accomplish the extra challenges that has been told in the video. The code snapshot is : https://w.trhou.se/hw5lza7zbu

4 Answers

dragos busuioc
dragos busuioc
24,908 Points

in for loop is students[i].name not .names

dragos busuioc
dragos busuioc
24,908 Points

another 2 things.In for loop instead making an asigment push every name in the student variable.When you declared student variable asign to it an empty array.See mdn push method documentation.The second thing in the if stament the variable report is nit declared in global scope.Is in the scope of getStudentReport function.declare report variable even in global scope.with diferent name preferable.good luck

Thankyou dragos,

Can you please tell me what does this code do:

report+= getStudentReport(students[student.indexOf(search)]);

.?

dragos busuioc
dragos busuioc
24,908 Points

+= is the shorthand for report = report + getStudentReport(...); Basically,asign to report the value returned from getStudentReport function.With += you dont overwrite the actual value.you just add it.But be carrefully.You make that asigned to a varible that dosnt exist in the global scope.

I did declared it globally and I understand the += purpose. Please explain the part after report+= i.e. getStudentReport(students[student.indexOf(search)]);

dragos busuioc
dragos busuioc
24,908 Points

you asigned to report the value returned from getStudentReport().In that case the value returned is report(that report avaible just in function scope)