javascript - 不断陷入循环
问题描述
为我的介绍类和我的 html 处理一些单词问题一直卡在我的代码的警报部分中的循环中。一旦它进入那里,无论我输入是否正确,它都不会回来。这是一个初学者课程,所以我们才刚刚进入循环和开关,所以请保持基本。提前致谢!
var custOwed, numCust, dayTotal;
var woodTotal, alumTotal, steelTotal;
var rate;
var woodCount = 0;
var alumCount = 0;
var steelCount = 0;
var woodAccum = 0;
var alumAccum = 0;
var steelAccum = 0;
var anotherOrder = "yes";
var woodRate = 10;
var alumRate = 15;
var steelRate = 25;
var errorFlag = 0;
anotherOrder = prompt("Another Order", "yes or no");
while (anotherOrder == "yes") {
poleType = prompt("What type of pole would you like today?", "wood, aluminum, or steel");
numFeet = prompt("How many feet?", "10");
numFeet = parseInt(numFeet);
switch (poleType) {
case "wood":
woodCount = woodCount + 1;
woodAccum = woodAccum + numFeet;
rate = woodRate;
break;
case "aluminum":
alumCount = alumCount + 1;
alumAccum = alumAccum + numFeet;
rate = alumRate;
break;
case "steel":
steelCount = steelCount + 1;
steelAccum = steelAccum + numFeet;
rate = steelRate;
break;
default:
errorFlag = 1;
break;
}
if (errorFlag == 1) {
alert("You typed " + poleType + " the only choices were wood, aluminum, or steel");
anotherOrder = "yes";
} else {
custOwed = numFeet * rate;
alert("You Owe" + custOwed);
anotherOrder = prompt("Another Customer?", "yes or no");
}
}
numCust = woodCount + alumCount + steelCount;
woodTotal = woodAccum * woodRate;
alumTotal = alumAccum * alumRate
steelTotal = steelAccum * steelRate
dayTotal = woodTotal + alumTotal + steelTotal;
document.write("Number of Customers: " + numCust);
document.write("<br>Wood Customers: " + woodCount);
document.write("<br>Total Feet of Wood: " + woodAccum);
document.write("<br>Total owed of Wood: $" + woodTotal.toFixed(2));
document.write("<br>Aluminum Customers: " + alumCount);
document.write("<br>Total Feet of Aluminum: " + alumAccum);
document.write("<br>Total owed of Aluminum: $" + alumTotal.toFixed(2));
document.write("<br>Steel Customers: " + alumCount);
document.write("<br>Total Feet of Steel: " + alumAccum);
document.write("<br>Total owed of Steel: $" + alumTotal.toFixed(2));
document.write("<br>Total owed from the day: $" + dayTotal.toFixed(2));
解决方案
推荐阅读
- r - 为什么在函数中使用 tidycensus get_decennial() 会失败?
- r - 使用 lapply 转置列的一部分并将其作为新列添加到数据框中
- python - 如何以编程方式返回关键字的位置(行和列)
- javascript - R闪亮中的ID和类组合的Javascript问题
- c++ - 将空参数列表函数从 C 转换为 C++
- javascript - 角度构建文件未捆绑在 dist 文件夹中
- c - 从睡眠中唤醒主线程
- google-cloud-platform - 如何使用谷歌云存储在多个谷歌云实例之间同步号码?
- rcpp - Rcpp:如何获取 rcpp 中可空矩阵的行/列数
- python - Python - 未来和上一个日历季度