Skip to content
Advertisement

The number of people cannot be initialized in the word chain game

This is a word chain game I made. When the game is over, the text is initialized. Other texts are initialized fine, but the text in span.number-of-people is not. In the console window console.log(numberOfPeople.textContent); It looks like it has been initialized. But why is the number not erased from the screen?

JavaScript
JavaScript

Advertisement

Answer

It is working. But then you’re calling gameStart(). Which does this:

JavaScript

So the code is successfully clearing the text in that element and then immediately putting it back again.

You probably also meant to reset the number variable when ending the game:

JavaScript

Keep in mind of course that this will likely lead you to start re-thinking some UX. Because while this “works”, the use of prompt() will block the UI from updating, and then immediately after promt() the new value is again used. So the code still never visually empties that field.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement