如何比较两个变量并设置第三个变量的值

How to compare two variables and set a value of a third variable

本文关键字:变量 三个 设置 两个 何比较 比较      更新时间:2023-09-26

我有这个功能,我似乎不能去工作。我想让它比较两个变量并设置第三个变量的值。

var win_lose;
var this_roll = $('#past')[0].childNodes[9].textContent;
var last_roll = $('#past')[0].childNodes[9].textContent;
function compare() {
    if (!(this_roll == last_roll)) {
        win_lose = 'lose';
    } else {
        win_lose = 'win';
    }
    console.log(win_lose);
}

你真的调用了这个函数吗?

var this_roll = $('#past')[0].childNodes[9].textContent;
var last_roll = $('#past')[0].childNodes[9].textContent;
function compare(this_roll, last_roll) {
    var win_lose;  //added new variable here
    if (this_roll != last_roll) {
        win_lose = 'lose';
    } else {
        win_lose = 'win';
    }
    return win_lose;
}
var res = compare(this_roll, last_roll);
console.log(res);

我也重写了你的if语句,不需要检查相等然后反转。

我也会像我一样将参数传递给函数