WORKING LIMBO MENU

var resetActive = 1;
var testingMode = 0;
var infoToShow = 1;

function CDAuto() {
  var myCurrentSeed = "0";
  var myNextSeed = "0";
  var myNextId = "0";
  var stopped = true;
  var checkReset = 0;
  var maxLose = 0;
  var loseInfo = [];
  var checkHunAfter = [0];
  var checkHunFound = true;
  var maxPayout = [0];
  var logPayout = [[2, 0, 0, 22], [3, 0, 0, 29], [4, 0, 0, 38], [5, 0, 0, 54], [6, 0, 0, 54], [7, 0, 0, 54], [8, 0, 0, 54], [9, 0, 0, 54], [10, 0, 0, 138], [15, 0, 0, 1005], [20, 0, 0, 1005], [25, 0, 0, 1005], [30, 0, 0, 1005], [50, 0, 0, 1005], [80, 0, 0, 1005], [99, 0, 0, 1005], [120, 0, 0, 1005], [180, 0, 0, 1225]];
  var payoutSelect = [[2, 2.2, 22, 15], [3, 1.6, 30, 3000], [5, 1.25, 60, 500], [10, 1.125, 100, 750], [120, 1.0086, 1000, 10]];

  this.resetSet = (levelRes) => {
    if (levelRes == 3) {
      this.randSel = rand(0, payoutSelect.length, randSel);
      this.nextBetSwap = rand(0, payoutSelect[this.randSel][3]);
      this.payLoud = payoutSelect[this.randSel][0];
      this.multiplier = payoutSelect[this.randSel][1];
      this.numLosin = payoutSelect[this.randSel][2];
      this.baseBet = getStartBet(originalbalance, this.multiplier, this.numLosin, this.payLoud);
    }
    if (levelRes == 2) {
      this.actResetSeed = true;
      stopped = false;
      this.tostopped = false;
      this.betNum = 0;
      this.loseStop = 0;
      loseInfo = [];
      this.resetSeed = parseFloat(document.querySelector('#resetSeed').value);
      this.stopWin = parseFloat(document.querySelector('#stoppinwin').value);
      runningbalance = parseFloat(document.querySelector('#betamount').value);
      originalbalance = runningbalance;
      this.payLoud = parseFloat(document.querySelector('#payoutR').value);
      this.multiplier = parseFloat(document.querySelector('#multiplier').value);
      this.numLosin = parseFloat(document.querySelector('#losingnumb').value);
      this.baseBet = getStartBet(originalbalance, this.multiplier, this.numLosin, this.payLoud);
      if (this.baseBet === "low") {
        console.log('Sorry bet seems too low...');
        this.stop();
      } else if (this.baseBet === "multi") {
        console.log('Sorry multiplier seems too low');
        this.stop();
      }
    }
    if (levelRes >= 1) {
      maxLose = -this.baseBet;
      this.loseCount = 1;
      this.currentBet = this.baseBet;
      lbg.payout = this.payLoud;
    }
  }

  this.resolveBet = (betlog) => {
    this.betNum += 1;
    runningbalance += betlog.profitAmount;
    this.logInfo("numbets", "val");
    this.servNonce = betlog.nonce;
    this.gamePayout = betlog.gameValue / 100;
    if (infoToShow !== 1) {
      checkPayout(this.gamePayout, logPayout);
    }
    if (maxPayout[0] <= this.gamePayout) {
      maxPayout = [this.gamePayout, this.servNonce, this.betNum];
    }
    if (this.gamePayout >= 120 && checkHunFound === false) {
      checkHunAfter.push("\nN: " + checkHunAfter[0] + " Ne: " + this.servNonce + "  Val: " + this.gamePayout + "  ID: " + myNextId);
      checkHunFound = true;
    }
    if ((this.servNonce - 10) === this.resetSeed) {
      getSeed(2).then((resu) => { myNextSeed = resu; });
      getSeed(3).then((resu) => { myNextId = resu; });
    }
    if (betlog.winAmount > 0) {
      if (this.servNonce >= this.resetSeed) {
        this.actResetSeed = true;
      }
      loseInfo.push([this.loseCount, Math.abs(maxLose), this.currentBet, lbg.payout, this.gamePayout]);
      if (this.tostopped === true) {
        this.logInfo("bigwins", "val");
      } else {
        this.logInfo("wins", "val");
      }
      this.resetSet(1);
    } else {
      lbg.payout = this.payLoud;
      this.currentBet = this.currentBet * this.multiplier;
      this.loseCount += 1;
      maxLose += -this.currentBet;
      if (Math.abs(maxLose) >= originalbalance) {
        this.logInfo("lose", "val");
      }
    }
    if (this.actResetSeed && resetActive === 1) {
      if (this.servNonce >= 10) {
        DoSeedChange(myNextSeed, "Limbo", myNextId);
        getSeed(1).then((resu) => { myCurrentSeed = resu; });
        sleep(1000);
      } else {
        checkHunAfter[0] += 1;
        checkHunFound = false;
        this.actResetSeed = false;
        getSeed(2).then((resu) => { myNextSeed = resu; });
        getSeed(3).then((resu) => { myNextId = resu; });
      }
    }

  this.cplay = () => {
    if (!stopped) {
      lbg.bet(this.currentBet)
        .then(this.resolveBet)
        .then(() => {
          this.cplay();
        })
        .catch((errorBet) => {
          if (errorBet === "Error: Amount invalid") {
            console.log("WOWOWOW way too lowww");
            this.stop();
          } else if (errorBet === "Error: system_error") {
            console.log("Low option, maybe too low amount or multiplier");
            this.stop();
          } else {
            console.log("Betting ERROR:\n" + errorBet + "\nWill try to continue...");
          }
          this.cplay();
        });
    }
  }
}
this.start = () => {
  console.log('Getting BaseBet...');
  this.resetSet(2);
  console.log('Bet starting....');
  this.startButton.style.display = 'none';
  this.stopButton.style.display = '';
  this.stopNext.style.display = '';
  if (testingMode === 1) {
    var vTestInfo = 'Settings Value(' + this.multiplier + 'x) ' + this.payLoud + '(' + this.numLosin + '):' + this.baseBet + '\n';
    for (let j = 0; j < payoutSelect.length; j++) {
      vTestInfo += 'Value for ' + payoutSelect[j][0] + ':' + getStartBet(originalbalance, payoutSelect[j][1], payoutSelect[j][2], payoutSelect[j][0]) + '\n';
    }
    console.log(vTestInfo);

    this.stop();
  } else {
    setTimeout(this.cplay(), 2000);
  }
}

this.stop = () => {
  this.startButton.style.display = '';
  this.stopButton.style.display = 'none';
  this.stopNext.style.display = 'none';
  this.stopped = true;
}

this.nextstop = () => {
  this.stopNext.style.display = 'none';
  this.tostopped = true;
}

//info print func
this.logInfo = (style, val) => {
  var netNumber = runningbalance - originalbalance;
  var netPecentage = (netNumber / originalbalance) * 100;
  if (netPecentage >= this.stopWin) {
    style = "bigwins";
  }

  var loseInfo_s = sortByColumn(loseInfo, 0);
  var sortCount = loseInfo_s.length - 1;
  if (style === 'numbets') {
    if (infoToShow >= 2) {
      if ((this.betNum % 10 === 0 && infoToShow === 2) || this.betNum === 1) {
        console.log('Bet#' + this.betNum + '/' + this.loseCount + ': ' + clean_output(this.currentBet, 3) + " * " + clean_output(lbg.payout), 3);
      } else if (infoToShow === 3) {
        console.log('Bet#' + this.betNum + '/' + this.loseCount + ': ' + clean_output(this.currentBet, 3) + " * " + clean_output(lbg.payout, 3) + ' (' + clean_output(Math.abs(maxLose), 3) + ') - ' + this.gamePayout);
      }
    }
  } else {
    var consoleText = '---Win ' + loseInfo.length + ' After ' + this.betNum + ' Bets Info---\n';
    if (infoToShow >= 1) {
      consoleText += 'BaseBet: ' + clean_output(this.baseBet, 3) + '  InPlay: ' + originalbalance + '\n';
      consoleText += 'Profit: ' + clean_output(netPecentage, 3) + '% - ' + clean_output(netNumber, 3) + '\n';
    }
    if (infoToShow >= 2) {
      consoleText += 'Last    Losing Streak: ' + this.loseCount + '  Cost: ' + clean_output(Math.abs(maxLose), 3) + '\n';
      consoleText += 'Highest Losing Streak: ' + clean_output(loseInfo[getMax(loseInfo, 0, "max")][0], 3) + '  Cost: ' + clean_output(loseInfo[getMax(loseInfo, 4, "max")][1], 3) + '\n';
    }
    if (infoToShow >= 3) {
      var numTimeInf = 10;
      if (loseInfo_s.length >= numTimeInf) {
        var tmpCount = numTimeInf;
      } else {
        var tmpCount = loseInfo_s.length;
      }
      var consoleTextMore = '--- ' + tmpCount + ' Biggest Streak ---\n';
      for (var i = 0; i < tmpCount; i++) {
        consoleTextMore += '#' + clean_output(loseInfo_s[sortCount - i][0], 3) + ': ' + clean_output(loseInfo_s[sortCount - i][1], 3) + ' = ' + clean_output(loseInfo_s[sortCount - i][2], 3) + 'x' +
          clean_output(loseInfo_s[sortCount - i][3], 3) + '(' + clean_output(loseInfo_s[sortCount - i][4], 3) + ')\n';
      }
      consoleText += consoleTextMore;
      if (loseInfo.length >= 100) {
        consoleText += averageLose(loseInfo, "Lose  Streaks");
      } else {
        consoleText += '---More Info After 100(' + loseInfo.length + ')wins---\n';
      }
      if (this.betNum >= 5000) {
        consoleText += infoPayout(logPayout, "Payouts Info");
      } else {
        consoleText += '---More Info After More Bets(' + this.betNum + ')---\n';
      }
      consoleText += "\nCheck 120(" + (checkHunAfter.length - 1) + "):" + checkHunAfter[0] + "(" + this.servNonce + ")";
      consoleText += "\nmaxPayout:" + maxPayout + "   ";
    }
    if (style === 'bigwins') {
      consoleText += "\nCheck:" + checkHunAfter;
      console.log(consoleText + '\nWining so it stopped');
      this.stop();
    } else if (style === 'lose') {
      console.log(consoleText + '\nBig LOSE so it stopped');
      this.stop();
    } else {
      console.log(consoleText);
    }
  }
}

//layout(<div> replacement) part
const htmlToElement = function (html) {
  let template = document.createElement('template');
  html = html.trim();
  template.innerHTML = html;
  return template.content.firstChild;
}

//layout remove part
document.querySelector('#Limbo-control-0 > div.game-control-panel .game-coininput')
document.querySelector('#Limbo-control-0 > div.game-control-panel div.ui-input.small.is-bold')
document.querySelector('#Limbo-control-0 > div.game-control-panel > div > button.bet-button')

//layout add part
this.prevOpt = (view) => {
  if (document.getElementById('prevHoldR').style.display === "none") {
    this.previwPage.style.display = '';
  } else {
    this.previwPage.style.display = 'none';
  }
}
var TxtHold = 'height: 80%; width: 23.75rem; position: absolute; background-color: #131416; padding-left: 10px; overflow-y: scroll;';
  var TxtHold2 = '<div class="line" style="margin: 1rem .75rem 0;color: var(--primary-color);">More Options</div><div class="wrappin" style="width:95%;">';
  TxtHold2 += '<div class="ui-input small"><div class="input-label">Stop on Win %</div><div class="input-control"><input type="text" value="15" id="stoppinwin"></div></div>';
  TxtHold2 += '<div class="ui-input small"><div class="input-label">When to reset seed</div><div class="input-control"><input type="text" value="2000" id="resetSeed">'+
                      '<div class="button-group"><button onclick="resetOnOff(0);" id="resetSeedON" style="background:#5b6787;">ON</button><button onclick="resetOnOff(1);" id="resetSeedOFF">OFF</button></div></div></div>';
  TxtHold2 += '<div class="input-label" style="margin-top:15px;margin-left:15px;">Info Select</div><div class="button-group">'+
                '<button onclick="infoFunc(1);" id="info1" style="background:#5b6787;">Min</button>'+
                '<button onclick="infoFunc(2);" id="info2">Norm</button>'+
                '<button onclick="infoFunc(3);" id="info3">All</button></div>';
  TxtHold2 += '<div class="input-label" style="margin-top:15px;margin-left:15px;">Test Mode</div><div class="button-group">'+
                '<button onclick="testingOnOff(0);" id="testingON">ON</button>'+
                '<button onclick="testingOnOff(1);" id="testingOFF" style="background:#5b6787;">OFF</button></div>';
  TxtHold2 += '<br></div>';
  this.previwPage = htmlToElement('<div class="preview-inner-wrap" style="'+TxtHold+'" id="prevHoldR">'+TxtHold2+'</div>');
  
  var chPlayInButtons = '';
  chPlayInButtons += '<div class="button-group">';
  chPlayInButtons += '<button onclick="changeInPlay(0);">ALL</button>';
  chPlayInButtons += '<button onclick="changeInPlay(2);">1/2</button>';
  chPlayInButtons += '<button onclick="changeInPlay(3);">1/3</button>';
  chPlayInButtons += '</div>';
  
  var defaultButtons = '';
  defaultButtons += '<div class="button-group">';
  defaultButtons += '<button onclick="setdefaultV(1);">1</button>';
  defaultButtons += '<button onclick="setdefaultV(2);">2</button>';
  defaultButtons += '<button onclick="setdefaultV(3);">3</button>';
  defaultButtons += '<button onclick="setdefaultV(4);">4</button>';
  defaultButtons += '<button onclick="setdefaultV(5);">5</button>';
  defaultButtons += '</div>';

	this.tmpCal = ss.wallet.dict[ss.wallet.current].amount;
  this.justLine1 = htmlToElement('<div class="line" style="margin: 1rem .75rem 0;color: var(--primary-color);">Auto Settings</div>');
  
	this.funding = htmlToElement('<div class="ui-input small"><div class="input-label">In Play</div><div class="input-control"><input type="text" value="'+this.tmpCal+'" id="betamount">'+chPlayInButtons+'</div></div>');
	this.multiDiv = htmlToElement('<div class="ui-input small"><div class="input-label">Multiplier</div><div class="input-control"><input type="text" value="1.009" id="multiplier"></div></div>');
	this.payoutDiv = htmlToElement('<div class="ui-input small"><div class="input-label"><div class="label">Payout</div><div class="label-amount">Defaults</div></div>'+
                                    '<div class="input-control"><input type="text" value="120" id="payoutR">'+defaultButtons+'</div></div>');
  
	this.numloseDiv = htmlToElement('<div class="ui-input small"><div class="input-label">Numbers of Lose</div><div class="input-control"><input type="text" value="1400" id="losingnumb"></div></div>');
  
	this.startButton = htmlToElement('<button class="ui-button button-big s-conic start-auto" style="margin-top:15px"><div class="button-inner">Start Auto</div></button>');
	this.stopButton = htmlToElement('<button class="ui-button button-big s-conic2 stop-auto" style="margin-top:15px"><div class="button-inner">Stop Auto</div></button>');
	this.stopNext = htmlToElement('<button class="ui-button button-big s-conic stop-next" style="margin-top:15px"><div class="button-inner">Stop Next Win</div></button>');
	this.moreOpt = htmlToElement('<button class="ui-button button-normal more-opt" style="margin-top:15px"><div class="button-inner">More Options</div></button>');
	this.stopNext.style.display = 'none';
	this.stopButton.style.display = 'none';
	this.previwPage.style.display = 'none';

	//document.querySelector('#Limbo-control-0 > div.game-control-panel > div').appendChild(this.justLine1);
	document.querySelector('#Limbo-control-0 > div.game-control-panel > div').appendChild(this.funding);
	document.querySelector('#Limbo-control-0 > div.game-control-panel > div').appendChild(this.payoutDiv);
	document.querySelector('#Limbo-control-0 > div.game-control-panel > div').appendChild(this.multiDiv);
	document.querySelector('#Limbo-control-0 > div.game-control-panel > div').appendChild(this.numloseDiv);
	document.querySelector('#Limbo-control-0 > div.game-control-panel > div').appendChild(this.moreOpt);
	document.querySelector('#Limbo-control-0 > div.game-control-panel > div').appendChild(this.startButton);
	document.querySelector('#Limbo-control-0 > div.game-control-panel > div').appendChild(this.stopButton);
	document.querySelector('#Limbo-control-0 > div.game-control-panel > div').appendChild(this.stopNext);
  
	document.querySelector('div.game-view').appendChild(this.previwPage);

	this.startButton.onclick = this.start;
	this.stopButton.onclick = this.stop;
	this.stopNext.onclick = this.nextstop;
  
	this.moreOpt.onclick = this.prevOpt;

//function to seed reset
  async function getSeed(val1) {
    var nextSeedResult = await fetch("https://bc.game/api/single/game/seed/Limbo/next-hash/", {
      "headers": {
      "accept": "application/json, text/plain, */*",
      "accept-language": "en-US,en;q=0.9",
      "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"99\", \"Microsoft Edge\";v=\"99\"",
      "sec-ch-ua-mobile": "?0",
      "sec-ch-ua-platform": "\"Windows\"",
      "sec-fetch-dest": "empty",
      "sec-fetch-mode": "cors",
      "sec-fetch-site": "same-origin"
      },
      "referrer": window.location.href,
      "referrerPolicy": "strict-origin-when-cross-origin",
      "body": null,
      "method": "GET",
      "mode": "cors",
      "credentials": "include"
    }).then(res => res.clone().json());

    var currentSeed = nextSeedResult.data.currentSeedHash;
    var nextSeedId = nextSeedResult.data.nextSeedHash;
    
    if(val1 == 1){ return currentSeed.clientSeed; }
    else if(val1 == 2){ return nextSeedId.clientSeed; }
    else if(val1 == 3){ return nextSeedId.seedId; }
    else { await DoSeedChange(nextSeedId.clientSeed, "Limbo", nextSeedId.seedId); }
  }
  async function DoSeedChange(clientseed, gameName, nextSeedId) {
    fetch("https://bc.game/api/single/game/seed/change/", {
      "headers": {
      "accept": "application/json, text/plain, */*",
      "accept-language": "en-US,en;q=0.9",
      "content-type": "application/json",
      "sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"99\", \"Microsoft Edge\";v=\"99\"",
      "sec-ch-ua-mobile": "?0",
      "sec-ch-ua-platform": "\"Windows\"",
      "sec-fetch-dest": "empty",
      "sec-fetch-mode": "cors",
      "sec-fetch-site": "same-origin"
      },
      "referrer": window.location.href,
      "referrerPolicy": "strict-origin-when-cross-origin",
      "body": "{\"clientSeed\":\""+ clientseed +"\",\"gameName\":\""+ gameName +"\",\"nextSeedId\":" + nextSeedId + "}",
      "method": "POST",
      "mode": "cors",
      "credentials": "include"
    }).then(res => res.clone().json());
    console.log('Reseting Seed...');
  }
}

function infoFunc(check){
  if(check == 1){//click off
    var tmp = '#info1';
    var tmp2 = '#info2';
    var tmp3 = '#info3';
    infoToShow = 1;
  } else if(check == 2) {
    var tmp = '#info2';
    var tmp2 = '#info1';
    var tmp3 = '#info3';
    infoToShow = 2;
  } else {
    var tmp = '#info3';
    var tmp2 = '#info2';
    var tmp3 = '#info1';
    infoToShow = 3;
  }
  document.querySelector(tmp).style.backgroundColor = "#5b6787"
  document.querySelector(tmp2).style.backgroundColor  = "#31343c"
  document.querySelector(tmp3).style.backgroundColor  = "#31343c"
}

function testingOnOff(check){
  if(check == 1){//click off
    var tmp = '#testingON';
    var tmp2 = '#testingOFF';
    testingMode = 0;
  } else {
    var tmp = '#testingOFF';
    var tmp2 = '#testingON';
    testingMode = 1;
  }
  document.querySelector(tmp).style.backgroundColor = "#31343c"
  document.querySelector(tmp2).style.backgroundColor  = "#5b6787"
}

function resetOnOff(check){
  if(check == 1){//click off
    var tmp = '#resetSeedON';
    var tmp2 = '#resetSeedOFF';
    resetActive = 0;
  } else {
    var tmp = '#resetSeedOFF';
    var tmp2 = '#resetSeedON';
    resetActive = 1;
  }
  document.querySelector(tmp).style.backgroundColor = "#31343c"
  document.querySelector(tmp2).style.backgroundColor  = "#5b6787"
}

function changeInPlay(set){
  var val = 0;
  if(set == 0){
    val = ss.wallet.dict[ss.wallet.current].amount;
  } else if(set == 2){
    val = clean_output(document.querySelector('#betamount').value/2,6);
  } else if(set == 3){
    val = clean_output(document.querySelector('#betamount').value/3,6);
  }
  document.querySelector('#betamount').value = val;
}

function setdefaultV(set){
  if(set == 1){
    document.querySelector('#payoutR').value = 2;
    document.querySelector('#multiplier').value = 2.2;
    document.querySelector('#losingnumb').value = 23;
  } else if(set == 2){
    document.querySelector('#payoutR').value = 3;
    document.querySelector('#multiplier').value = 1.6;
    document.querySelector('#losingnumb').value = 35;
  } else if(set == 3){
    document.querySelector('#payoutR').value = 5;
    document.querySelector('#multiplier').value = 1.25;
    document.querySelector('#losingnumb').value = 60;
  } else if(set == 4){
    document.querySelector('#payoutR').value = 10;
    document.querySelector('#multiplier').value = 1.125;
    document.querySelector('#losingnumb').value = 140;
  } else if(set == 5){
    document.querySelector('#payoutR').value = 120;
    document.querySelector('#multiplier').value = 1.009;
    document.querySelector('#losingnumb').value = 1400;
  }
}

function clean_output(val,val2){
  var tmp = (precision) => (nbr, _, __, powerOf10) => 
    nbr === 0
      ? 0
      : (
          powerOf10 = 10 ** (precision - Math .ceil (Math .log10 (Math .abs (nbr)))), 
          Math .round (nbr * powerOf10) / powerOf10
        )
   var tmp2 = tmp(val2);
   return tmp2(val);
}

function rand( min, max, check){
	if(isNaN(check)){
  	var txt = Math.floor(Math.random() * (max - min + 1)) + min;
  } else {
  	do{
    	var txt = Math.floor(Math.random() * (max - min + 1)) + min;
    }while(txt==check)
  }
  return txt
}

function checkPayout(val1,val2){
  for (var i = 0; i < val2.length; i++) {
    if(val1 >= val2[i][0]) {
      if(val2[i][1] >= val2[i][2]) { val2[i][2]=val2[i][1];}
      val2[i][1] = 0;
    } else { val2[i][1] += 1;}
  }
}
  
function getMax(val,val2,MinMax){
  var sum = [];
  for (var i = 0; i < val.length; i++) {
    sum.push(val[i][val2]);
  }
  if(MinMax == "max"){
    var index = sum.indexOf(Math.max(...sum));
  } else {
    var min = Math.min(...sum);
    var index = sum.indexOf(min);
  }
  return index;
}

function sortByColumn(a, colIndex){
  a.sort(sortFunction);
  function sortFunction(a, b) {
      if (a[colIndex] === b[colIndex]) {
          return 0;
      }
      else {
          return (a[colIndex] < b[colIndex]) ? -1 : 1;
      }
  }
  return a;
}

function getCount(vArray,vArraySlot,vLow,vHigh,vStyle){
  var sum = 0;
  for (var i = 0; i < vArray.length; i++) {
    if(vStyle == "inbetween"){//check inbetween
      if(vArray[i][vArraySlot] >= vLow && vArray[i][vArraySlot] <= vHigh){ sum += 1;}
    } else if(vStyle == "higher") {//check all higher then low
      if(vArray[i][vArraySlot] >= vLow){ sum += 1;}
    } else if(vStyle == "lower") {//check all lower then high
      if(vArray[i][vArraySlot] <= vHigh){ sum += 1;}
    }
  }
  return sum;
}

function infoPayout(vArray,vTxt){
  var tmpTxt = "--- "+vTxt+" ---\n";
  for (var i = 0; i < vArray.length; i++) {
    tmpTxt += vArray[i][0]+':'+(vArray[i][2]+1)+' ';
    if(i % 6 == 0 && i != 0){ tmpTxt += "\n";}
  }
  tmpTxt +=  '\n';
  return tmpTxt;
}

function averageLose(vArray,vTxt){
  var min = vArray[getMax(vArray,0,"min")][0];
  var max = vArray[getMax(vArray,0,"max")][0];
  var numWin = vArray.lenght+1;
  var baseVal = max-min;
  var set1 = Math.floor(baseVal-(baseVal*(1-(5/100))));
  var set2 = Math.floor(baseVal-(baseVal*(1-(10/100))));
  var middel = Math.floor((min+max)/2);
  
  
  var set3 = numWin-(numWin*(1-(15/100)));
  var base1 = max;
  do{
    base1 = base1-set2;
    var tmp = getCount(vArray,0,base1,max,"inbetween");
    
  }while(tmp >= set3)
  var base2 = min;
  do{
    base2 = base2+set2;
    var tmp = getCount(vArray,0,min,base2,"inbetween");
    
  }while(tmp >= set3)
  
  
  var txtOut = "--- "+vTxt+" ---\n";
  txtOut += "base1: "+base1+' base2: '+base2+"\n";
  txtOut += base2+'-'+base1+':'+getCount(vArray,0,base2,base1,"inbetween")+"\n";
  
  
  txtOut += "middel: "+middel+"\n";
  txtOut += min+'-'+max+':'+getCount(vArray,0,min,max,"inbetween")+"\n";
  
  txtOut += "Min-Mid "+min+'-'+middel+':'+getCount(vArray,0,min,middel,"inbetween")+" \n";
  txtOut += "Min-Mid+15% "+min+'-'+Number(middel+(set2+set1))+':'+getCount(vArray,0,min,Number(middel+(set2+set1)),"inbetween")+"\n";
  
  txtOut += "Min-Max-15% "+min+'-'+Number(max-(set2+set1))+':'+getCount(vArray,0,min,Number(max-(set2+set1)),"inbetween")+" \n";
  txtOut += "Min-Max-25% "+min+'-'+Number(max-((set2*2)+set1))+':'+getCount(vArray,0,min,Number(max-((set2*2)+set1)),"inbetween")+" \n";
  
  txtOut += '+'+middel+':' +getCount(vArray,0,middel,0,"higher")+' ';
  txtOut += '-'+middel+':' +getCount(vArray,0,0,middel,"lower")+' ';
  txtOut += '-100:' +getCount(vArray,0,0,100,"lower")+'\n';
  return txtOut;
}
  
function sleep(milliseconds) {
  const date = Date.now();
  let currentDate = null;
  do {
    currentDate = Date.now();
  } while (currentDate - date < milliseconds);
}

function getStartBet(vInPlay, vMulti, vLoses, vPayout){
  var bet; var baseBet;
  var moneyPit; var DiffTest;
  var countX = 0;
  do {
    if (countX == 0) {
      bet = vInPlay * (0.00644/10000);
      baseBet = bet;
      moneyPit = 0 + bet;
      DiffTest = 2;
    } else {
      var tmpHold = (Math.abs(moneyPit-vInPlay)/moneyPit)*100;
      if(moneyPit >= vInPlay){
        var tmpRan = Math.floor(Math.random() * ((50+countX) - 25 + 1) + 25);
        tmpRan = countX%25;
        if(tmpHold >= 0.1){ bet = baseBet*(1-(tmpHold/100));}
        else { bet = baseBet*(1-(tmpRan/100));}
        baseBet = bet;
        moneyPit = 0 + bet;
      } else {
        if(tmpHold >= 0.1){ bet = baseBet*(1+((tmpHold/1.5)/100));}
        else { bet = baseBet*1.2;}
        baseBet = bet;
        moneyPit = 0 + bet;
      }
    }
    
    for (let j = 0; j < (vLoses-1); j++) {
      bet = bet * vMulti;
      moneyPit = moneyPit + bet;
    }
    if(moneyPit >= vInPlay){ DiffTest=2;}
    else{ DiffTest = ((Math.abs(moneyPit-vInPlay))/((moneyPit+vInPlay)/2))*100;}
    countX++;
    if(vInPlay >= 10){ tmpRan = vInPlay/10;}
    else { tmpRan = vInPlay*10}
  } while ((DiffTest >= (1/(tmpRan)))&&(countX<=100));
  do {
  	if (isNaN(baseBet)) { return baseBet="bad_values"; }
    else {
      if(baseBet.toFixed(6) <= 0.0000001){ return baseBet="low";}
      bet = Number(baseBet.toFixed(8));
      moneyPit = 0 + bet;
      for (let j = 0; j < (vLoses-1); j++) {
        var isLosin = (bet*vPayout)-(moneyPit);
        bet = bet * vMulti;
        moneyPit = moneyPit + bet;
        if(isLosin <= 0){ return baseBet="multi-low";}
        if(isLosin >= vInPlay){ return baseBet="multi-high";}
      }
      if(moneyPit >= vInPlay){ baseBet=Number(baseBet.toFixed(8))-0.00000001;}
    }
  } while (moneyPit >= vInPlay);
  baseBet = Number(baseBet.toFixed(8));
  if(baseBet.toFixed(6) <= 0.0000001){ return baseBet="low";}
  return baseBet;
}

const cdauto = new CDAuto();    Hi, why am I getting this error? Unexpected token ')'. Expected ';' after variable declaration.