I'm having an implementation issue running a script. The outcome I am trying to achieve is as follows.
The script should run by clicking hi_button on the website, wait until btc_digits has finished loading as a result of clicking hi_button (although for this I use setTimeout to give btc_digits plenty of time to finish loading, I am unsure if a ready() function would be better, or how to implement this), then check another output, btc_lose. If btc_lose does not meet a condition for any of the 5 iterations the script starts back at the first iteration function one(). If all 5 iterations meet the condition then another script becomes active. The process then starts over again.
I have tried many variations, none of which work. The most up to date javascript/jQuery is as follows.
rollDice = function() { 
  $('#double_your_btc_bet_hi_button').click() 
  setTimeout(one(), 2500) 
  one() 
  function one() { 
    if ($('#double_your_btc_lose').html() !== '') { 
      $('#double_your_btc_bet_hi_button').click() 
      setTimeout(two(), 2500) 
      two() 
    } else { 
      one() 
    } 
    function two() { 
      if ($('#double_your_btc_lose').html() !== '') { 
          $('#double_your_btc_bet_hi_button').click() 
          setTimeout(three(), 2500) 
          three() 
      } else { 
          one() 
      } 
      function three() { 
        if ($('#double_your_btc_lose').html() !== '') { 
            $('#double_your_btc_bet_hi_button').click() 
            setTimeout(four(), 2500) 
            four() 
        } else {  
            one() 
        } 
        function four() { 
          if ($('#double_your_btc_lose').html() !== '') { 
            $('#double_your_btc_bet_hi_button').click() 
            setTimeout(five(), 2500) 
            five() 
          } else { 
            one() 
          } 
          function five() { 
            if ($('#double_your_btc_lose').html() !== '') { 
                alert("function2") 
            } else { 
                one() 
            } 
          } 
        } 
      } 
    } 
  } 
} 
rollDice()
My original question can be found on Programmers at: https://softwareengineering.stackexchange.com/q/240657/131983
 
     
    