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

Marsha Annon
Marsha Annon
8,072 Points

Four in a row Object-Oriented JS challenge [Spaces are not showing & no errors in console]

Hi, I'm not sure where I have gone wrong, but I have a board and a token, but no spaces on my board. I have checked the final solution for the Spaces and Board classes and mine seems exactly the same, perhaps I am looking in the wrong place??

Here's what I have

class Space {
    constructor(x, y) {
        this.x = x;
        this.y = y;
        this.id = `space-${x}-${y}`;
        this.token = null;
        this.diameter = 76;
        this.radius = this.diameter / 2;
    }

    drawSVGSpace() {    
        const svgSpace = document.createElementNS("http://www.w3.org/2000/svg", "circle");
        svgSpace.setAttributeNS(null, "id", this.id);
        svgSpace.setAttributeNS(null, "cx", (this.x * this.diameter) + this.radius);
        svgSpace.setAttributeNS(null, "cy", (this.y * this.diameter) + this.radius);
        svgSpace.setAttributeNS(null, "r", this.radius - 8);
        svgSpace.setAttributeNS(null, "fill", "black");
        svgSpace.setAttributeNS(null, "stroke", "none");

        document.getElementById("mask").appendChild(svgSpace);     
    }
}
class Board {
    constructor() {
        this.row = 6;
        this.column = 7;
        this.spaces = this.createSpaces();
    }

    createSpaces() {
        const spaces = [];

        for(let x = 0; x < this.columns; x++) {
            const column = [];

            for(let y = 0; y < this.rows; y++) {
                const space = new Space(x, y);
                column.push(space);
            }
            spaces.push(column);
        }
        return spaces;
    }

    drawHTMLBoard() {
        for(let column of this.spaces) {
            for(let space of column){
                space.drawSVGSpace();
            }
        }
    }
}