"缺少)后参数列表”;错误--Can't Find A Bug
"Missing ) After Argument List" Error -- Can't Find A Bug
我是JavaScript的新手,所以如果我犯了一个愚蠢的错误,我很抱歉,但我在这里找不到错误。我正在创建一个"选择你自己的冒险"类型的游戏,它进展顺利,直到我添加了一些do/while循环和if/else语句。
我已经测试了一段时间,通过消除过程,我发现只有当我有以下行时才会出现错误:
if (worst === (options[0] || options[1])) {
options.splice(2, 0, best);
但就我的一生而言,我找不到错误。
如果有帮助的话,这就是整个脚本:
var options = ["STRENGTH", "SPEED", "SMARTS"];
alert("Before we begin our journey, let's learn a little bit about you.");
var user = prompt("What is your name?").toUpperCase();
do {
var bestLoop = false;
var best = prompt("So " + user + ", what is your greatest ability, STRENGTH, SPEED, or SMARTS?").toUpperCase();
if (best === ("STRENGTH" || "SPEED" || "SMARTS")) {
var offset = options.indexOf(best);
if (offset != -1) {
options.splice(offset, 1);
}
} else {
alert("Please choose either STRENGTH, SPEED, or SMARTS as your greatest ability.");
bestLoop = true;
}
} while (bestLoop);
alert("Great! So " + best + " is yor greatest ability.");
do {
var worstLoop = false;
var worst = prompt("So which is your greatest weakness, " + options[0] + " or " + options[1] + "?").toUpperCase();
if (worst === (options[0] || options[1])) {
options.splice(2, 0, best);
} else {
alert("Please choose either " + options[0] + " or " + options[1] " as your greatest weakness.");
worstLoop = true;
}
} while (worstLoop);
alert("Great. So your name is " + user + ", " + best + " is your greatest ability, and " + worst + " is your greatest weakness.");
如果我忽略了什么,我再次道歉,但这已经让我疯了几个小时,我似乎找不到问题所在。
行中缺少一个"+"
alert("Please choose either " + options[0] + " or " + options[1]" as your greatest weakness.");
所以应该是:
alert("Please choose either " + options[0] + " or " + options[1] + " as your greatest weakness.");
这使翻译感到困惑。
建议:如果你能找到一种配置文本编辑器的方法,让它与jslint或jshint一起使用。这样可以为您找到丢失的运算符或括号,从而节省大量时间
相关文章:
- Can not find Jquery
- 因果报应:Can't find变量:exports
- "缺少)后参数列表”;错误--Can't Find A Bug
- Can't find socket.io.js
- 不能调用JavaScript ReferenceError: Can't find variable
- Javascript with Selenium WebDriver: "Can't find var
- safari ReferenceError: Can't find variable changestyledi
- ReferenceError: Can't find variable: google"检查是否未定义
- 添加复选框,can't find up('checkboxgroup')
- jQueryMobile pageInit, "Can't find variable?
- Getting ReferenceError: Can't find variable: require rea
- ReferenceError: Can't find variable: define at ..With
- ReferenceError: Can't find variable: require
- application.js can't find jquery.ui.effect-blind
- Phone Gap 'ReferenceError: Can't find variable: devi
- ReferenceError: Can't find variable: _e_0uWl - Browser &
- 参考错误:Can't find variable: bootbox
- ReferenceError: Can't find variable error
- 参考错误:Can't find variable: dataKeys
- 引用错误:Can't find variable