How to compare two variables in javascript

cbh1608

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);

McMuffinDK

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);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

compare two variables in an if statement javascript

How to compare two variables in php

How do I compare values from two variables that got their values as result of mapping other variables in JavaScript?

How to compare two string in javascript?

How to compare two tm (from ctime) variables

how to compare two string variables in pandas?

How to compare two string variables in Makefile

How to Compare two BigInteger variables as unsigned?

How to compare two variables using If Else in NSIS?

How to compare two datetime variables correctly?

AWK: How to Compare Two Variables with Regular Expression

in a sequence, how to compare two added variables?

How to swap two variables in JavaScript

JavaScript if statement able to compare two variables with identical values

How to Compare two Arrays are Equal using Javascript?

how to compare two strings in javascript if condition

how to compare two string dates in javascript?

How to compare two arrays in JavaScript? But the key is a string

How to compare two object array in javascript?

How to compare two time values by pure JavaScript?

How to compare two objects in javascript and get difference?

how to compare values of two array in javascript

How to compare two different date formats in javascript

How to compare objects of two different arrays in javascript

How to use ggplot to make a qqplot to compare the distribution of two variables?

How do I compare two string variables in an 'if' statement in Bash?

How do I compare class type of two different variables for equality?

How to compare two variables with creating your own function?

Compare two lists of variables in python