Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript time-out
    text
    copied!<p>Every time I run this segment of code in a sandbox environment I time-out and eventually crash. I've run it through mutliple IDEs and am still unable to find any syntax errors. If anyone is seeing something that I'm not, I'd very much appreciate the input.</p> <pre><code>//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" &amp;&amp; questionState != "no"); i++; } while (questionState == "yes"); totalAverage = runningAverage / i; // parse through each element of carModel, milesDriven, gallonsUsed for (var j = 0; j &lt;= i; j++) { //determine performance standards based upon M.P.G of vehicle if (milesperGallon[j] &gt;= 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] &gt;= 31 &amp;&amp; milesperGallon[j] &lt; 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] &gt;= 27 &amp;&amp; milesperGallon[j] &lt; 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] &gt;= 23 &amp;&amp; milesperGallon[j] &lt; 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] &gt;= 22 &amp;&amp; milesperGallon[j] &lt; 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] &gt;= 19 &amp;&amp; milesperGallon[j] &lt; 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] &gt;= 17 &amp;&amp; milesperGallon[j] &lt; 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] &gt;= 15 &amp;&amp; milesperGallon[j] &lt; 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] &gt;= 13 &amp;&amp; milesperGallon[j] &lt; 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] &gt;= 0 &amp;&amp; milesperGallon[j] &lt; 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 &gt;= 0) { document.writeln("You have" + " " + i + " " + "vehicles." + " " + "Between them they average" + " " + totalAverage + " " + "miles per gallon."); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload