Jus*_*osh 1 javascript function skip
我正在为一个入门编程课程的项目工作,所以我使用的是基本的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.");
}
Run Code Online (Sandbox Code Playgroud)
你有;
if(numTrees == 5, 10)?
Run Code Online (Sandbox Code Playgroud)
错误的逗号导致if评估truthy表达式,10因此它总是通过测试,测试5,6,7,8,9 或10;
if(numTrees >= 5 && numTrees <= 10)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1346 次 |
| 最近记录: |