2013-06-29 46 views
0

我對JavaScript很陌生,所以如果我犯了一個愚蠢的錯誤,我很抱歉,但是我在這裏找不到錯誤。我正在創建一個'選擇你自己的冒險'類遊戲,並且在我添加了一些do/while循環和if/else語句之前,它已經很流暢了。「Missing)Argument List」錯誤 - 找不到Bug

我一直在測試了一段時間,並通過消除過程中,我發現了錯誤,只有當我有這樣的行出現:

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."); 

我再次道歉,如果有什麼我忽略了,但是這已經快把我逼瘋了幾個小時,我似乎無法到找到問題。

+2

我不認爲這是在做你認爲它在做'最佳===(「STRENGTH」||「SPEED」||「SMARTS」),也不是這條線最糟===(options [ 0] || options [1])' – elclanrs

+0

我測試過了,現在系統工作得很好。它檢查響應是否是上述之一,並且如果沒有再次回到問題。有沒有更好的方法來做到這一點? – weirdalexv

+0

你是如何測試它的?這不符合你的要求,因爲這沒有意義。非空字符串評估爲true。只有第一個將根據條件進行評估。檢查一下,沒有任何提示:http://jsbin.com/ihiqeg/1/edit – elclanrs

回答

0

你缺少的管線

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。這可以通過爲您找到缺少的操作員或括號來節省大量時間。

+0

非常感謝,對於這樣一個愚蠢的問題感到抱歉! – weirdalexv

+0

沒問題,很高興它爲你工作。 –