0

"use strict";
var red_id = document.getElementsByClassName("btn btn-danger btn-lg btn-block betButton")[0];
var green_id = document.getElementsByClassName("btn btn-success btn-lg btn-block betButton")[0];
var black_id = document.getElementsByClassName("btn btn-inverse btn-lg btn-block betButton")[0];

document.getElementById('betAmount').value = 'NaN';
red_id.id = 'red';
green_id.id = 'green';
black_id.id = 'black';

setInterval(automated, 40000);

function automated() {

var roll_history = $('#past')[0].childNodes[9].textContent;
var roll_hisLast = $('#past')[0].childNodes[8].textContent;
var red_button = document.getElementById('red');
var black_button = document.getElementById('black');
var base_bet = 1;

function thisRoll(roll_history) {
	var this_roll;
	if (roll_history === 0) {
		this_roll = 'green';
	} else if ((roll_history >= 1) && (roll_history <= 7)) {
		this_roll = 'red';
	} else if ((roll_history >= 8) && (roll_history <= 14)) {
		this_roll = 'black';
	}
	return this_roll;
}
var thisRoll = thisRoll(roll_history);
console.log(thisRoll);

function LastRoll(roll_hisLast) {

	var last_roll;
	if (roll_hisLast === 0) {
		last_roll = 'green';
	} else if ((roll_hisLast >= 1) && (roll_hisLast <= 7)) {
		last_roll = 'red';
	} else if ((roll_hisLast >= 8) && (roll_hisLast <= 14)) {
		last_roll = 'black';
	}
	return last_roll;
}
var lastRoll = LastRoll(roll_hisLast);
console.log(LastRoll);

function compare(thisRoll, lastRoll) {
	var win_lose;
	if (thisRoll !== lastRoll) {
		win_lose = 'lose';
	} else {
		win_lose = 'win';
	}
	return win_lose;
}
var winLose = compare(thisRoll, lastRoll);
console.log(winLose);

var input_last = document.getElementById('betAmount').value;

function betInputLast(input_last) {

	var last;
	last = input_last;
	return last;
}
var lastXX = betInputLast(input_last);
console.log(lastXX);

function betInputLastX(lastXX) {

	var fix_X;
	if (isNaN(lastXX)) {
		fix_X = base_bet;
	}
	return fix_X;
}
var lastX = betInputLastX(X);
console.log(lastX);

function betInput(winLose) {

	var x;
	if (winLose === 'win') {
		x = base_bet;
	} else if (winLose === 'lose') {
		x = lastX * 2;
	}
	return x;
}
var X = betInput(winLose);
console.log(X);

var bet_input = document.getElementById('betAmount').value = X;

function bet(thisRoll, X) {

	var log;
	if (thisRoll === 'red') {
		red_button.click();
		log = 'Betting ' + X + ' on red';
	} else if (thisRoll === 'black') {
		black_button.click();
		log = 'Betiing ' + X + ' on black';
	}
	return log;
}
var Log = bet(thisRoll, X);
console.log(Log);
}
<div class="roulette"><div class="well text-center" style="margin-bottom:10px;margin-top:25px; padding: 20px;">
			<div class="progress text-center" style="height:50px;margin-bottom:10px;">
				<span id="banner">Rolling in 24.93...</span>
				<div class="progress-bar progress-bar-danger" id="counter" style="width: 83.1432%; overflow: hidden;"></div>
			</div>
			<div id="case" style="margin-bottom: 15px; background-position: -208px 0px;">
				<div id="pointer"></div>
			</div>
			<div id="past">
              <div data-rollid="696912" class="ball ball-0">0</div>
              <div data-rollid="696913" class="ball ball-8">9</div>
              <div data-rollid="696914" class="ball ball-1">5</div>
              <div data-rollid="696915" class="ball ball-1">3</div>
              <div data-rollid="696916" class="ball ball-1">6</div>
              <div data-rollid="696917" class="ball ball-8">14</div>
              <div data-rollid="696918" class="ball ball-1">3</div>
              <div data-rollid="696919" class="ball ball-8">11</div>
              <div data-rollid="696920" class="ball ball-8">10</div>
              <div data-rollid="696921" class="ball ball-0">0</div>
            </div>
			<div style="margin: 20px 0px;">
			</div>
			<div class="form-group">
				<div class="input-btn bet-buttons">
					<span class="balance"> 
						<span>Balance: </span>
						<span id="dongers_r"></span>
						<span id="balance_r" class="">15020</span> <i style="cursor:pointer; margin-left: 5px;" class="fa fa-refresh noselect" id="getbal_r"></i>
					</span>
					<input type="text" class="form-control input-lg" placeholder="Bet amount..." id="betAmount">
					<button type="button" class="btn btn-danger betshort" data-action="clear">Clear</button>
					<button type="button" class="btn btn-default betshort" data-action="10">+10</button>
					<button type="button" class="btn btn-default betshort" data-action="100">+100</button>
					<button type="button" class="btn btn-default betshort" data-action="1000">+1000</button>
					<button type="button" class="btn btn-default betshort" data-action="half">1/2</button>
					<button type="button" class="btn btn-default betshort" data-action="double">x2</button>
					<button type="button" class="btn btn-primary betshort" data-action="max">Max</button>
				</div>
			</div>
		</div>
		<div class="row text-center">
			<div class="col-xs-4 betBlock" style="padding-right:0px">
				<div class="panel panel-default bet-panel" id="panel11-7-b">
					<div class="panel-heading">
						<button class="btn btn-danger btn-lg  btn-block betButton" data-lower="1" data-upper="7"><span> 1 to 7</span><span></span></button>
					</div>
				</div>
				<div class="panel panel-default bet-panel" id="panel1-7-m">
					<div class="panel-body" style="padding:0px">
						<div class="my-row">
							<div class="text-center"><span class="mytotal">0</span></div>
						</div>
					</div>
				</div>
				<div class="panel panel-default bet-panel" id="panel1-7-t">
					<div class="panel-body" style="padding:0px">
						<div class="total-row">
							<div class="text-center">Total bet: <span class="total">24485</span></div>
						</div>
					</div>
				</div>
			</div>
			<div class="col-xs-4 betBlock">
				<div class="panel panel-default bet-panel" id="panel0-0-b">
					<div class="panel-heading">
						<button class="btn btn-success btn-lg  btn-block betButton" data-lower="0" data-upper="0">0</button>
					</div>
				</div>
				<div class="panel panel-default bet-panel" id="panel0-0-m">
					<div class="panel-body" style="padding:0px">
						<div class="my-row">
							<div class="text-center"><span class="mytotal">0</span></div>
						</div>
					</div>
				</div>
				<div class="panel panel-default bet-panel" id="panel0-0-t">
					<div class="panel-body" style="padding:0px">
						<div class="total-row">
							<div class="text-center">Total bet: <span class="total">13780</span></div>
						</div>
					</div>
				</div>
			</div>
			<div class="col-xs-4 betBlock" style="padding-left:0px">
				<div class="panel panel-default bet-panel" id="panel8-14-b">
					<div class="panel-heading">
						<button class="btn btn-inverse btn-lg  btn-block betButton" data-lower="8" data-upper="14"><span> 8 to 14</span><span></span></button>
					</div>
				</div>
				<div class="panel panel-default bet-panel" id="panel8-14-m">
					<div class="panel-body" style="padding:0px">
						<div class="my-row">
							<div class="text-center"><span class="mytotal">0</span></div>
						</div>
					</div>
				</div>
				<div class="panel panel-default bet-panel" id="panel8-14-t">
					<div class="panel-body" style="padding:0px">
						<div class="total-row">
							<div class="text-center">Total bet: <span class="total">6572</span></div>
						</div>
					</div>
				</div>
			</div>
		</div></div>

The function that dosen't work is function betInput(winLose) that have to multiply with 2 if winLose = 'lose' it happens first time but after that the output is only 2, were it should be multiplyed with 2.

I know this is peace of cake but i can't seem to figure it out.

7
  • 1
    Did you check your console? It gives an Uncaught TypeError. Commented Nov 16, 2016 at 15:17
  • 1
    Well you never update lastX.... Commented Nov 16, 2016 at 15:18
  • @crowes yeah i checked, and that is what confused me. There was no error Commented Nov 16, 2016 at 15:18
  • @Crowes @McMuffin I think the error is coming because you've haven't added any HTML in the snippet & the js code is trying to perform DOM operation on betAmount Commented Nov 16, 2016 at 15:21
  • @epascarello so what you are saying is, that if i change the function betInputLastX to function betInputLastX(lastXX) { var fix_X; if (isNaN(lastXX)) { fix_X = base_bet; } else { fix_X = lastXX; } return fix_X; } var lastX = betInputLastX(X); console.log(lastX); it will work? Commented Nov 16, 2016 at 15:23

1 Answer 1

1

I think there are a few problems here. I'm not totally sure what you are shooting for but these things might help.

I think you my have some scope issues here. The function automated gets called every so often on a timer. Each time that function is called all of the variables that are defined within automated using var statements are fresh, new variables. Consider defining lastX and X before the definition of automated. This way those values will be remembered for each successive call to automated.

Next consider the function betInputLastX. The only case that is covered is the initial case where the parameter value is NaN. I think that there should be an else branch that would assign X to fix_X. If this is not done the fix_X value is returned as undefined, and not useful in successive functions.

With these changes the output will give a sequence that looks some thing like NaN, 2, 4, 8, 16, 32, .... I'm not sure that all your problems are solved at this point but I hope these suggestions can get back on track to continue developing.

Sign up to request clarification or add additional context in comments.

1 Comment

I have tried change it to function betInputLastX(lastXX) { var fix_X; if (isNaN(lastXX)) { fix_X = base_bet; } else { fix_X = lastXX; } return fix_X; } var lastX = betInputLastX(X); console.log(lastX); but that didn't work. I don't think i can define lastX and X before automated because i need lastX to be the value of X from the previous time the function was executed, and i need X to be updated by betInput every time automated is executed to fill in var bet_input = document.getElementById('betAmount').value = X;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.