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 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
229,732 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 :)