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 Build an Object Challenge, Part 2 Solution

Pranav Mathur
Pranav Mathur
3,419 Points

Please explain how you are getting data from student.js file to student_report.js file?

Do I need to import something, like we do with classes in JAVA?

jsdevtom
jsdevtom
16,963 Points

Include context and files so that I can help

1 Answer

Peter Larson
Peter Larson
6,412 Points

I had the same question, and here's what I think is going on... I think that you don't have to import students.js because the place where this code is actually running is the index.html file. When you run index.html, you've already called the students.js file, so when student_report.js runs, you've got students.js in memory, and the students array has already been loaded into memory, or at least its existence has been noted by your code. Your student_report.js code then has you calling for data in an array called students and knows there's one out there. If you were to call student_report.js before students.js, you would probably have problems. I think this also means that you could have a bunch of functions written in another .js file and you'd be able to call them as long as that file was called in the index.html file before the code where you try to use those functions.