本文介绍了ReferenceError:赋值中的左侧无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的摇滚剪刀游戏代码(称为折腾)如下:
my code for a rock paper scissors game (called toss) is as follows:
var toss = function (one,two) {
if(one = "rock" && two = "rock") {
console.log("Tie! Try again!");
}
// more similar conditions with `else if`
};
当我输入参数时
toss("rock","rock")
我得到此错误代码:
如何解决?此错误意味着什么以及发生此错误时的其他情况?
How to fix it? What this error means and what other cases when this error can happen?
推荐答案
您必须使用 ==
进行比较(或甚至 ===
,如果你想比较类型)。单个 =
用于分配。
You have to use ==
to compare (or even ===
, if you want to compare types). A single =
is for assignment.
if (one == 'rock' && two == 'rock') {
console.log('Tie! Try again!');
}
这篇关于ReferenceError:赋值中的左侧无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!