0

I want to match two variables.

var this_roll;

and

var last_roll;

I have this code, that i want the output of "win" or "losse". The output should be "win" if last_roll and this_roll have the same value and "lose" if not

"use strict";
var x;
var win_losse = 'losse';
var last_roll;
var last_bet;
var this_roll = $('#past')[0].childNodes[9].textContent;
var bet_input = document.getElementById('betAmount').value=x;
var roll_time = $('#banner')[0].childNodes[0].textContent;
var base_bet = 5;

function thisRoll() {

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

function compare() {

	if (this_roll == last_roll) {
		win_losse = 'win';
	} else {
		win_losse = 'losse';
	}
	console.log(win_lose);
}

function lastRoll() {

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

function bet() {

	if (win_losse == 'win') {
		x = base_bet;
	} else if (win_losse == 'losse') {
		x = last_bet * 2;
	}
}
console.log(x);

4
  • "it didn't seem to work" doesn't tell us anything. What result did you get, and what result did you expect? Separately, please pull the various disconnected parts above into a single minimal reproducible example, ideally a runnable one using Stack Snippets (the <> toolbar button). Commented Nov 12, 2016 at 9:57
  • "and this sets the value of this_roll" Nothing in the code block following that sets the value of this_roll. Commented Nov 12, 2016 at 9:58
  • Thanks just saw that, i have changed it Commented Nov 12, 2016 at 10:05
  • I have edited the post and put it into it Commented Nov 12, 2016 at 10:26

1 Answer 1

1

This works for sure

"use strict";
//Removed the global x variable
//Removed the global win_lose variable
var last_roll = $('#past')[0].childNodes[8].textContent;
var last_bet;
var this_roll = $('#past')[0].childNodes[9].textContent;
var bet_input = document.getElementById('betAmount').value=x;
//Removede the Roll_time variable because it wasn't used
var base_bet = 5;

function ThisRoll(this_roll) {
	var rollhisThis; //Added a local  variable
	if (this_roll === 0) {
		rollhisThis = 'green';
	} else if ((this_roll >= 1) && (this_roll <= 7)) {
		rollhisThis = 'red';
	} else if ((this_roll >= 8) && (this_roll <= 14)) {
		rollhisThis = 'black';
	}
	return rollhisThis; //Added return
}
var thisRoll = ThisRoll(this_roll); //Added a new global variable
console.log(thisRoll);

function LastRoll(last_roll) {

	var rollhisLast; //Added a local variable
	if (last_roll === 0) {
		rollhisLast = 'green';
	} else if ((last_roll >= 1) && (last_roll <= 7)) {
		rollhisLast = 'red';
	} else if ((last_roll >= 8) && (last_roll <= 14)) {
		rollhisLast = 'black';
	}
	return rollhisLast; //Added return
}
var lastRoll = LastRoll(last_roll); //Added a new global variable
console.log(LastRoll);

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

function bet() {

	if (win_losse == 'win') {
		x = base_bet;
	} else if (win_losse == 'losse') {
		x = last_bet * 2;
	}
}
console.log(x);

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.