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

Jaemin Yi
Jaemin Yi
4,040 Points

In the getStudentReport function, is there a purpose to the "student" parameter?

When he makes the function:

function getStudentReport(student)

Is there a purpose for the "student" parameter? It's not accessing the "student" variable from inside the For loop (student = students[i]), is it?

If it doesn't serve a purpose, why not just leave the function parentheses blank? Why type "student" in there at all? Thank you!

1 Answer

Diane Kerstein
Diane Kerstein
5,155 Points

Your question has to do with scope.

If the getStudentReport function runs w/o the parameter, what would student.name print? What would students[i].name print if you put that in the function? Nothing because the object array of students and the object student are outside the scope of the function. You must hand the function the data it needs by way of parameter.