Javascript超时
每次我在沙箱环境中运行这段代码时,我都会超时并最终崩溃。我已经在多个IDE中运行了它,但仍然找不到任何语法错误。如果有人看到我没有看到的东西,我会非常感谢你的意见Javascript超时,javascript,Javascript,每次我在沙箱环境中运行这段代码时,我都会超时并最终崩溃。我已经在多个IDE中运行了它,但仍然找不到任何语法错误。如果有人看到我没有看到的东西,我会非常感谢你的意见 //assign variables to memory var carModel = new Array() var milesDriven = new Array() var gallonsUsed = new Array() var milesperGallon = new Array() var questionState,
//assign variables to memory
var carModel = new Array()
var milesDriven = new Array()
var gallonsUsed = new Array()
var milesperGallon = new Array()
var questionState, epaRating, conditionofVehicle, totalAverage;
var runningAverage = 0;
var i = 0;
do {
//retrieve basic information about vehicle from standard input: model, miles, gallons
carModel[i] = prompt("What type of vehicle do you drive?");
milesDriven[i] = parseInt(prompt("How many miles have you
driven with this vehicle?"));
gallonsUsed[i] = parseInt(prompt("How many gallons of gas have you used when driving this vehicle?"));
//calculate miles per gallon
milesperGallon[i] = milesDriven[i] / gallonsUsed[i];
runningAverage = runningAverage + milesperGallon[i];
do {
questionState = prompt("Do you have any more vehicles that you would like to enter? If yes, type 'yes'. If no, type 'no'.");
} while (questionState != "yes" && questionState != "no");
i++;
} while (questionState == "yes");
totalAverage = runningAverage / i;
// parse through each element of carModel, milesDriven, gallonsUsed
for (var j = 0; j <= i; j++) {
//determine performance standards based upon M.P.G of vehicle
if (milesperGallon[j] >= 38) {
conditionofVehicle = "Good";
epaRating = 10;
//output the performance standards to user
document.writeln("Your" + " " + carModel[j] + " " + "receives" + " " + milesperGallon[j] + " " + "miles per gallon.");
document.writeln("Based upon this metric your vehicle is in" + " " + conditionofVehicle + " " + "condition and has a EPA rating of" + " " + epaRating + ".");
} else if (milesperGallon[j] >= 31 && milesperGallon[j] < 38) {
conditionofVehicle = "Good";
epaRating = 9;
//output the performance standards to user
document.writeln("Your" + " " + carModel[j] + " " + "receives" + " " + milesperGallon[j] + " " + "miles per gallon.");
document.writeln("Based upon this metric your vehicle is in" + " " + conditionofVehicle + " " + "condition and has a EPA rating of" + " " + epaRating + ".");
} else if (milesperGallon[j] >= 27 && milesperGallon[j] < 31) {
conditionofVehicle = "Good";
epaRating = 8;
//output the performance standards to user
document.writeln("Your" + " " + carModel[j] + " " + "receives" + " " + milesperGallon[j] + " " + "miles per gallon.");
document.writeln("Based upon this metric your vehicle is in" + " " + conditionofVehicle + " " + "condition and has a EPA rating of" + " " + epaRating + ".");
} else if (milesperGallon[j] >= 23 && milesperGallon[j] < 27) {
conditionofVehicle = "Fair";
epaRating = 7;
//output the performance standards to user
document.writeln("Your" + " " + carModel[j] + " " + "receives" + " " + milesperGallon[j] + " " + "miles per gallon.");
document.writeln("Based upon this metric your vehicle is in" + " " + conditionofVehicle + " " + "condition and has a EPA rating of" + " " + epaRating + ".");
} else if (milesperGallon[j] >= 22 && milesperGallon[j] < 23) {
conditionofVehicle = "Fair";
epaRating = 6;
//output the performance standards to user
document.writeln("Your" + " " + carModel[j] + " " + "receives" + " " + milesperGallon[j] + " " + "miles per gallon.");
document.writeln("Based upon this metric your vehicle is in" + " " + conditionofVehicle + " " + "condition and has a EPA rating of" + " " + epaRating + ".");
} else if (milesperGallon[j] >= 19 && milesperGallon[j] < 22) {
conditionofVehicle = "Fair";
epaRating = 5;
//output the performance standards to user
document.writeln("Your" + " " + carModel[j] + " " + "receives" + " " + milesperGallon[j] + " " + "miles per gallon.");
document.writeln("Based upon this metric your vehicle is in" + " " + conditionofVehicle + " " + "condition and has a EPA rating of" + " " + epaRating + ".");
} else if (milesperGallon[j] >= 17 && milesperGallon[j] < 19) {
conditionofVehicle = "Fair";
epaRating = 4;
//output the performance standards to user
document.writeln("Your" + " " + carModel[j] + " " + "receives" + " " + milesperGallon[j] + " " + "miles per gallon.");
document.writeln("Based upon this metric your vehicle is in" + " " + conditionofVehicle + " " + "condition and has a EPA rating of" + " " + epaRating + ".");
} else if (milesperGallon[j] >= 15 && milesperGallon[j] < 17) {
conditionofVehicle = "Bad";
epaRating = 3;
//output the performance standards to user
document.writeln("Your" + " " + carModel[j] + " " + "receives" + " " + milesperGallon[j] + " " + "miles per gallon.");
document.writeln("Based upon this metric your vehicle is in" + " " + conditionofVehicle + " " + "condition and has a EPA rating of" + " " + epaRating + ".");
} else if (milesperGallon[j] >= 13 && milesperGallon[j] < 15) {
conditionofVehicle = "Bad";
epaRating = 2;
//output the performance standards to user
document.writeln("Your" + " " + carModel[j] + " " + "receives" + " " + milesperGallon[j] + " " + "miles per gallon.");
document.writeln("Based upon this metric your vehicle is in" + " " + conditionofVehicle + " " + "condition and has a EPA rating of" + " " + epaRating + ".");
} else if (milesperGallon[j] >= 0 && milesperGallon[j] < 13) {
conditionofVehicle = "Bad";
epaRating = 1;
//output the performance standards to user
document.writeln("Your" + " " + carModel[j] + " " + "receives" + " " + milesperGallon[j] + " " + "miles per gallon.");
document.writeln("Based upon this metric your vehicle is in" + " " + conditionofVehicle + " " + "condition and has a EPA rating of" + " " + epaRating + ".");
} else {
document.writeln(" ");
}
}
// check to make sure there is an input value
if (totalAverage >= 0) {
document.writeln("You have" + " " + i + " " + "vehicles." + " " + "Between them
they average" + " " + totalAverage + " " + "miles per gallon.");
}
//为内存分配变量
var carModel=新数组()
var milesDriven=新数组()
var gallonsUsed=新数组()
var milesperGallon=新数组()
var状态、分离、车辆状况、总平均值;
var runningAverage=0;
var i=0;
做{
//从标准输入中检索有关车辆的基本信息:型号、英里、加仑
carModel[i]=提示(“您驾驶哪种类型的车辆?”);
milesdrive[i]=parseInt(提示(“您行驶了多少英里
用这辆车驾驶?);
加仑消耗量[i]=parseInt(提示(“您驾驶此车辆时使用了多少加仑汽油?”);
//计算每加仑英里数
milesperGallon[i]=行驶里程[i]/加仑[i];
runningAverage=runningAverage+米力斯贝加隆[i];
做{
questionState=提示(“您是否还有其他车辆要进入?如果有,请键入“是”。如果没有,请键入“否”。”;
}而(questionState!=“是”&&questionState!=“否”);
i++;
}而(提问状态=“是”);
totalAverage=runningAverage/i;
//解析carModel、milesDriven、gallonsUsed的每个元素
对于(变量j=0;j=38){
车辆状况=“良好”;
epaating=10;
//将性能标准输出给用户
document.writeln(“您的“+”+carModel[j]+“+”接收“+”+milesperGallon[j]+“+”英里每加仑”);
document.writeln(“根据此指标,您的车辆处于车辆+++”状态,且EPA评级为“++”+”);
}else如果(米尔斯佩格隆[j]>=31&&米尔斯佩格隆[j]<38){
车辆状况=“良好”;
epaating=9;
//将性能标准输出给用户
document.writeln(“您的“+”+carModel[j]+“+”接收“+”+milesperGallon[j]+“+”英里每加仑”);
document.writeln(“根据此指标,您的车辆处于车辆+++”状态,且EPA评级为“++”+”);
}else如果(米尔斯佩尔加隆[j]>=27和米尔斯佩尔加隆[j]<31){
车辆状况=“良好”;
epaating=8;
//将性能标准输出给用户
document.writeln(“您的“+”+carModel[j]+“+”接收“+”+milesperGallon[j]+“+”英里每加仑”);
document.writeln(“根据此指标,您的车辆处于车辆+++”状态,且EPA评级为“++”+”);
}否则如果(米莱斯佩尔加隆[j]>=23&&米莱斯佩尔加隆[j]<27){
车辆条件=“公平”;
epaating=7;
//将性能标准输出给用户
document.writeln(“您的“+”+carModel[j]+“+”接收“+”+milesperGallon[j]+“+”英里每加仑”);
document.writeln(“根据此指标,您的车辆处于车辆+++”状态,且EPA评级为“++”+”);
}else如果(米尔斯佩尔加隆[j]>=22和米尔斯佩尔加隆[j]<23){
车辆条件=“公平”;
epaating=6;
//将性能标准输出给用户
document.writeln(“您的“+”+carModel[j]+“+”接收“+”+milesperGallon[j]+“+”英里每加仑”);
document.writeln(“根据此指标,您的车辆处于车辆+++”状态,且EPA评级为“++”+”);
}else如果(米尔斯佩尔加隆[j]>=19和米尔斯佩尔加隆[j]<22){
车辆条件=“公平”;
分离=5;
//将性能标准输出给用户
document.writeln(“您的“+”+carModel[j]+“+”接收“+”+milesperGallon[j]+“+”英里每加仑”);
document.writeln(“根据此指标,您的车辆处于车辆+++”状态,且EPA评级为“++”+”);
}else如果(米尔斯佩尔加隆[j]>=17和米尔斯佩尔加隆[j]<19){
车辆条件=“公平”;
epaating=4;
//将性能标准输出给用户
document.writeln(“您的“+”+carModel[j]+“+”接收“+”+milesperGallon[j]+“+”英里每加仑”);
document.writeln(“根据此指标,您的车辆处于车辆+++”状态,且EPA评级为“++”+”);
}else如果(米尔斯佩尔加隆[j]>=15和米尔斯佩尔加隆[j]<17){
车辆状况=“坏”;
epaating=3;
//将性能标准输出给用户
document.writeln(“您的“+”+carModel[j]+“+”接收“+”+milesperGallon[j]+“+”英里每加仑”);
document.writeln(“根据此指标,您的车辆处于车辆+++”状态,且EPA评级为“++”+”);
}否则如果(米尔斯佩格隆[j]>=13&&米尔斯佩格隆[j]<15){
车辆状况=“坏”;
epaating=2;
//将性能标准输出给用户
document.writeln(“您的“+”+carModel[j]+“+”接收“+”+milesperGallon[j]+“+”英里每加仑”);
document.writeln(“根据此指标,您的车辆处于车辆+++”状态,且EPA评级为“++”+”);
}else如果(milesperGallon[j]>=0&&milesperGallon[j]<13){
车辆状况=“坏”;
分离=1;
//将性能标准输出给用户
document.writeln(“您的“+”+carModel[j]+“+”接收“+”+milesperGallon[j]+“+”英里每加仑”);
document.writeln(“根据此指标,您的车辆
milesDriven[i] = parseInt(prompt("How many miles have you
driven with this vehicle?"));
milesDriven[i] = parseInt(prompt("How many miles have you driven with this vehicle?"));
if (totalAverage >= 0) {
document.writeln("You have" + " " + i + " " + "vehicles." + " " + "Between them
they average" + " " + totalAverage + " " + "miles per gallon.");
}
if (totalAverage >= 0) {
document.writeln("You have" + " " + i + " " + "vehicles." + " " + "Between them they average" + " " + totalAverage + " " + "miles per gallon.");
}