Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Object-Oriented JavaScript: Challenge Building Constructor Methods and Generating Objects createSpaces() Method Solution

Tyler McDonald
Tyler McDonald
Full Stack JavaScript Techdegree Student 10,024 Points

Possible Error in the HTML Scripts?

Hi, please correct me if I'm wrong or misunderstanding, but I think I came across an error in the way the js files are loaded into the HTML with the scripts (i.e. <script src = "js/Board.js"></script>).

Whenever creating the Board class, and subsequently calling the Space class in order to create spaces for the board, I kept getting an error in the console Uncaught ReferenceError: Space is not defined.

After trying a series of fixes, I finally found one that worked. I went to the HTML file, move the <script src="js/Space.js"></script> before <script src = "js/Board.js"></script> and it finally worked!

Is this an error in the way the program files were set up, or is there a different/better solution than what I did? It seems really odd that the JS files would have to be structed in a specific way, but I could not find a better solution. Thank you!

Steven Parker
Steven Parker
216,891 Points

The order sensitivity may be a result of something in your code. If you'd like help finding it, make a snapshot of your workspace and post the link to it here.