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

Not a question, just my version of the answer.

There were bugs in my code so I followed along with the video until I got it to work

Instead of looping and running an if statement for each space in the column I filtered to find all the nulls. Next I ran an if to see if the array was empty. Then selected the last items in the array by subtracting 1 from the length.

    playToken () {

        let spaces = this.board.spaces;
        let activeToken = this.activePlayer.activeToken;
        let targetColumn = spaces[activeToken.columnLocation];
        let targetSpace = null;

        let openSpaces = targetColumn.filter(spaces => spaces.token === null);
        if (openSpaces.length > 0) {
            let targetSpace = openSpaces[openSpaces.length - 1];
            this.ready = false;
            activeToken.drop(targetSpace);
        }
    }

If you want to give feedback, cool!