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

Cannot return the state back to initial

Hello everyone! When I play one game and then click start game again, I cannot clear my ul with previous random phrase letter from the old game and then to add new li’s with letters created with new phrase. Any advice will be appreciated) what i need is to have the view of any new try the same as initial and user should be able to play again. Thank you! https://github.com/k-petite/project-8

1 Answer

Steven Parker
Steven Parker
243,318 Points

Your loop is attempting to index through a list and alter it at the same time, which will cause elements to be skipped over.

But there is a much easier way to clear an element, simply set its textContent property to an empty string:

  ul.textContent = "";    //removes all letters created in the previous game

Thank you, Steven! It worked)