basically im trying to make an automation script for a gambling website . if you know roulette game mode you would now that you have about 20 seconds to choose a color and 10 seconds for the outcome to appear each round . what im trying to do is making a while loop for the script to run until the balance reaches a certain amount . what im struggling with is using the set timeout function to make a delay every 30 seconds so the betting bot can bet each round basically it waits 30 seconds then the bot bets .
example :

```
do{
    delay 30 seconds amount 
    run bot()
}while(condition)

```

when i tried to use the set timeout function and used the script on the website its started betting infinitely and the whole thing crashed because the delay didn't happen correctly.
this is the code :

```
function Bot(bt, bc)
{

  l = ((document.getElementsByClassName("roulette-past-queue--previous-rolls-container horizontal-scroll")[0].innerText).length);
  f = document.getElementsByClassName("roulette-past-queue--previous-rolls-container horizontal-scroll")[0].innerText;
  number = f[l - 1];
  number = parseInt(number.replace(" ", ""));
  if (number >= 1 && number <= 7)
  {
    LastResult = "red";
  }
  if (number >= 8 && number <= 14)
  {
    LastResult = "black";
  }
  if (number == 0)
  {
    LastResult = "green";
  }
  if (LastResult == bc)
  {
    if (bc == "red")
    {
      document.getElementById('bet-input-r').value = bt;
      document.getElementById('roulette-btn-red').click();
    }
    else
    {
      document.getElementById('bet-input-r').value = bt;
      document.getElementById('roulette-btn-black').click();
    }

  }
  if (LastResult != bc)
  {
    if (bc == "red")
    {
      document.getElementById('bet-btn-double-r').click();
      document.getElementById('roulette-btn-black').click();
      bc = "black"
        bt = bt * 2

    }
    else
    {
      document.getElementById('bet-btn-double-r').click();
      document.getElementById('roulette-btn-red').click();
      bc = "red"
        bt = bt * 2
    }
  }

}

balance = document.getElementById('balance').innerHTML;
balance = parseInt(balance.replace(",", ""));
bet = 10
  TargetBalance = 99988
  document.getElementById('bet-input-r').value = bet;
betcolor = "black";
if (betcolor == "red")
{
  document.getElementById('roulette-btn-red').click();
}
else
{
  document.getElementById('roulette-btn-black').click();
}
//this is the looping part causing the problem i have deleted setTimout so you can see what i mean clearly
do
{
  // 30 seconds delay
  Bot(bet, betcolor)

}
while (balance < TargetBalance && balance > bet)

```