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

alborz
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
alborz
Full Stack JavaScript Techdegree Graduate 30,885 Points

I can't get the tic tac toe boxes to clear the board when a new game starts

So I have a tic tac toe game; when the player wins a win screen is displayed; on that screen is a new game button; when the user clicks that button, the board reappears, but the boxes are still filled in with the players moves -- I want the board to be clear so a new game can start. Here's my repo. Thanks!

https://github.com/amesbahi/tic-tac-toe

1 Answer

Steven Parker
Steven Parker
229,644 Points

You need to loop through the box elements to clear them.

I noticed at the beginning of newGame you have statements that appear to be intended to remove the box-filled classes from the box elements, but the collection (boxes) doesn't have a classList property itself. But if you use a loop which includes an index variable, and then use that variable to index into the collection, you can easily remove the classes from every individual box.

In jQuery, collections can be operated on with a single statement. If you've used jQuery before that may be the cause of the confusion.