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 Making the Game Interactive moveLeft() and moveRight() Methods Solution

moveRight() alternative, would this cause an issue?

 moveRight(){
        if (this.columnLocation < game.board.columns - 1) {
            this.htmlToken.style.left = this.offsetLeft + 76;
            this.columnLocation += 1;
        }
    }

I handled the column amount within my method rather than passing it as an argument. Tested and it works fine but just wondering it anyone can think of any possible issues with this solution?

I think I may of thought of one possible issue;

const game = new Game();

if the variable name for the game was changed in the app file then this solution would no longer be able to call this;

game.board.columns 

as it would only search for a game with the variable name 'game'.

2 Answers

Steven Parker
Steven Parker
220,634 Points

I think you've answered your own question! :+1:

You could, however, pass in the game object and still access the columns in the function:

moveRight(game){
    if (this.columnLocation < game.board.columns - 1) {
        this.htmlToken.style.left = this.offsetLeft + 76;
        this.columnLocation += 1;
    }
}

Brill thanks Steven, nice to have some confirmation :)