Learning java , game project, don't know what to do

Hi everyone, i started learning Js and doing small game rn , but the issue is that I can’t stop the loop. Loop should continue while gameState = true, once I click correct letter it should stop(just an example), but it doesn’t and I have no idea why tbh.

while (holder<999 && gameState) {
   setTimeout(
      SpawnLetter,
      holder * 500,
      letters[Math.floor(Math.random() * letters.length)],
      word
    );

   holder++;
}

This while loop is most likely going to run 998 times before you click on a correct letter and change gameState to false. Change it to holder<10 and you will see the letters stop after the 9th one.