1

I have this function which I use in Chrome Console. My question is how to edit the code so that this is executes every 10 seconds.

Thank you

var minValue = 1E-8,
    maxLoss = 10000000000000,
    aimedProfit = 10,
    maxOps = 500000000000000,
    endResult = 0,
    ops = 0,
    bet = function (a, b, c) {
          var seed = window.document.getElementById('next_client_seed').value;      
        $.get("?op=double_your_btc&m=" + (b ? "lo" : "hi") + "&stake=" + a + "&multiplier=2&jackpot=0&client_seed=" + seed, function (d) {
            d = d.split(":");
            $("#balance").html(d[3]);
            c(a, b, "w" === d[1])
        })
    }, martingale = function (a, b, c) {
        c || a >= maxLoss && 0 !== maxLoss ? (b = !b, newValue = minValue) : newValue = 2 * a;
        endResult = c ? endResult + a : endResult - a;
        console.log((c ? "+" : "-") + a);
        ops++;
        (ops < maxOps || 0 === maxOps) && (endResult < aimedProfit || 0 === aimedProfit) ? bet(newValue, b, martingale) :
            (console.log("Martingale finished in " + ops + " operations!"), console.log("Result: " + endResult))
    };
martingale(minValue, !1, !1);
EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179
  • 1
    Possible duplicate of http://stackoverflow.com/questions/2170923/whats-the-easiest-way-to-call-a-function-every-5-seconds-in-jquery – Cezary Wojcik Mar 17 '14 at 21:47

2 Answers2

2

You can use either setTimeout or setInterval.

With setInterval your code will look as follows:

var myFunction = function () {
    var minValue = 1E-8,
    maxLoss = 10000000000000,
    aimedProfit = 10,
    maxOps = 500000000000000,
    endResult = 0,
    ops = 0,
    bet = function (a, b, c) {
          var seed = window.document.getElementById('next_client_seed').value;      
        $.get("?op=double_your_btc&m=" + (b ? "lo" : "hi") + "&stake=" + a + "&multiplier=2&jackpot=0&client_seed=" + seed, function (d) {
            d = d.split(":");
            $("#balance").html(d[3]);
            c(a, b, "w" === d[1])
        })
    }, martingale = function (a, b, c) {
        c || a >= maxLoss && 0 !== maxLoss ? (b = !b, newValue = minValue) : newValue = 2 * a;
        endResult = c ? endResult + a : endResult - a;
        console.log((c ? "+" : "-") + a);
        ops++;
        (ops < maxOps || 0 === maxOps) && (endResult < aimedProfit || 0 === aimedProfit) ? bet(newValue, b, martingale) :
            (console.log("Martingale finished in " + ops + " operations!"), console.log("Result: " + endResult))
    };
    martingale(minValue, !1, !1);
};

setInterval(myFunction, 10000);
Minko Gechev
  • 25,304
  • 9
  • 61
  • 68
0

Try:

setInterval(funcion(){
  martingale(minValue, !1, !1);
}, 10000);
StackSlave
  • 10,613
  • 2
  • 18
  • 35