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 Object-Oriented JavaScript: Challenge Building Constructor Methods and Generating Objects Build the createSpaces() Method

Piotr Manczak
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Piotr Manczak
Front End Web Development Techdegree Graduate 29,747 Points

createSpaces()

To create this method I came up with this way of thinking: This method will need to return an array so I can start with creating an empty array for spaces objects. If I looked at the constructor of Space and I need two parameters: x and y, to generate them I can use double loop, outer with x's and inner with y's. then within the look I can call 'new Space' in order to create new Space object and as an input I could use current iteration of x and y. Then I only attach newly created Space to the array. At the end I return the array with all the spaces. I need 7 x's and 6 y's so I will end up with 42 spaces in total.