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 Rendering the Game Rendering the Spaces, Board, and Tokens Solution

Joseph Anson
Joseph Anson
14,447 Points

Would this for loop work fopr the drawHTMLBoard() ?

I am so confused. I realised my original for loop wouldn't work and without copying the code in the video I wanted to try it myself first.

Would the following code work?

    drawHTMLboard() {
        for (let i=0; i < spaces.length; i++) {
            for (let s=0; s < spaces[i].length; i++) {
                spaces[i][s].drawSVGSpace();
            }
        }
    }

Thank you

3 Answers

Steven Parker
Steven Parker
229,732 Points

It looks like you have a sound idea, but why not try it out and see for yourself? Testing it in place might help reveal any issues that need to be addressed.

Seth Kroger
Seth Kroger
56,413 Points

Your inner loop should have s++ instead of i++. Otherwise it should work.

Dzmitry Aliakseichyk
Dzmitry Aliakseichyk
12,290 Points

for (let i = 0; i < this.spaces.length; i++) { for (let x = 0; i < this.spaces[i].length; x++) { this.spaces[i][x].drawSVGSpace(); } } }

I suspect you also have to put 'this.' when referencing "spaces".