0
我想匹配两个变量。如何比较javascript中的两个变量
var this_roll;
和
var last_roll;
我有这样的代码,我想要的 “双赢” 或 “losse” 的输出。输出应该是 “双赢” 如果last_roll
和this_roll
具有相同的价值和 “输” 如果不是
"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() {
\t console.log(this_roll);
\t if (this_roll == 0) {
\t \t this_roll = 'green';
\t } else if ((this_roll >= 1) && (this_roll <= 7)) {
\t \t this_roll = 'red';
\t } else if ((this_roll >= 8) && (this_roll <= 14)) {
\t \t this_roll = 'black';
\t }
}
function compare() {
\t if (this_roll == last_roll) {
\t \t win_losse = 'win';
\t } else {
\t \t win_losse = 'losse';
\t }
\t console.log(win_lose);
}
function lastRoll() {
\t console.log(this_roll);
\t if (this_roll == 0) {
\t \t last_roll = 'green';
\t } else if ((this_roll >= 1) && (this_roll <= 7)) {
\t \t last_roll = 'red';
\t } else if ((this_roll >= 8) && (this_roll <= 14)) {
\t \t last_roll = 'black';
\t }
}
function bet() {
\t if (win_losse == 'win') {
\t \t x = base_bet;
\t } else if (win_losse == 'losse') {
\t \t x = last_bet * 2;
\t }
}
console.log(x);
*“它似乎没有工作”*没有告诉我们任何事情。你得到了什么结果,你期望得到什么结果?另外,请将上面各个断开的部分放到一个[mcve]中,理想情况下是使用Stack Snippets('<>'工具栏按钮)的** runnable **。 –
*“这将设置this_roll的值”*以下代码块中没有设置this_roll的值。 –
谢谢刚刚看到,我已经改变了它 – cbh1608