私は入門プログラミングクラスのプロジェクトに取り組んでいるので、基本的な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.");
}