Hello,
So I built a project today, it is a Typing Game I made on CodePen.
I used setInterval()
to repeatedly generate a random word as a <div>
, and then use setInterval()
again to make it move down the screen. The player needs to type out the letters in the word before the word reaches the bottom.
The gist of it is, every string that is generated and put onscreen also goes into an array inPlay
. Then every keydown
event adds the key value to an empty temp
string and simultaneously checks the inPlay
array for the presence of that string. Once an inPlay
string is found, it is removed from the DOM and from the inPlay
array, and the temp
string is reinitialized to ""
. Also, any word that reaches the bottom will automatically be removed.
There are two issues I am having with the code:
- I set the
setInterval()
that generates the word elements to 1800 ms. But for the first minute or so of the game, it seems to create them at much shorter intervals, flooding the screen with words. It only levels off and reaches a steady rate after a minute or so. - Sometimes, usually when there are a lot of words on the screen, some words will not register. I will literally type the exact word, and it won’t respond. Is this because there are so many
setIntervals
running, and something something event loop?
Thank you. Have a nice day.