我正在爲一個介紹性編程類的項目工作,所以我使用基本的JavaScript。這是我們的第一個功能項目,由於某種原因,我似乎無法使其工作。我在程序啓動之前調用了所有的變量並創建了函數,但由於某種原因它跳過了我的程序中的函數運行。任何幫助,將不勝感激。Javascript跳過功能
這只是我的程序的開始,我不想編寫代碼的其餘部分,直到我找出爲什麼這個部分被破壞,這就是爲什麼程序沒有做任何事情,但如果它沒有關閉窗口通過測試。
// 1 Declare Variables
var numTrees;
var counter = 0;
var answer = "no";
function treeFunction(answer, counter, numTrees) {
while (answer == "no" && counter < 3) {
if (numTrees == 5, 10) {
answer = "yes";
} else if (numTrees < 5 || numTrees > 10) {
alert("That is an incorrect value.\nThe sample size should be less than 5 or greater than 10.\nPlease try again.");
answer = "no";
numTrees = prompt("Please reenter the amount of trees in your sample.");
counter + 1;
}
}
if (answer == "no") {
alert("You have entered an incorrect number too many times.\nThe Program will now end.");
window.open('', '_self', '');
window.close();
} else if (answer == "yes") {
return;
}
}
// 2 Prompt the Instructor for the number of Trees
numTrees = prompt("How many trees are in your sample?");
alert("You have entered: " + numTrees);
treeFunction(answer, counter, numTrees)
document.write(numTrees); {
document.write("<br/> <br/>" + "End of Program.");
}
我沒有運行的代碼,但我也注意到你失蹤後'treeFunction分號(答案,counter,numTrees)' – kei 2012-08-01 15:13:20
'if(numTrees == 5,10)'是什麼意思? – 2012-08-01 15:14:02
@kei:不會引起任何問題 – 2012-08-01 15:14:28