我有这样的代码:
var maneuver = {
"diceOnHand" : 0,
"rollResult" : [],
"diceRoll" : function(diceNumber) {
dicePool.action.take(diceNumber);
this.diceOnHand += diceNumber;
for (i = 1; i <= this.diceOnHand; i++) {
this.rollResult.push(Math.floor(Math.random() * 6) + 1);
}
this.rollResult.ForEach(function(entry) {
if (entry > 2 and entry < 6) {
//GO TO STRIKE POOL
dicePool.strike.add(1);
} else
if (entry == 6) {
//GO TO CHARGE POOL
dicePool.charge.add(1);
}
});
/*
for (j of this.rollResult) {
if (j > 2 and j < 6) {
//GO TO STRIKE POOL
dicePool.strike.add(1);
} else
if (j == 6) {
//GO TO CHARGE POOL
dicePool.charge.add(1);
}
}*/
}
}变量entry和j在for循环中总是被视为“意外标识符”。我不知道他们为什么会被这样对待,即使他们应该是合法的标识符afaik。
发布于 2015-11-12 04:39:01
JS没有and逻辑运算符。使用&&。
j > 2 && j < 6
发布于 2015-11-12 05:08:42
vp_arth的话--我在这里看到了另一个错误:
if (entry > 2 and entry < 6) {
//GO TO STRIKE POOL
dicePool.strike.add(1);
} else应:
if (entry > 2 && entry < 6) {
//GO TO STRIKE POOL
dicePool.strike.add(1);
} else要进一步阅读,请查看以下内容:JavaScript逻辑运算符
https://stackoverflow.com/questions/33664305
复制相似问题