这是我到目前为止写的代码。如果有人能告诉我为什么它不能运行,我将非常感激。我试过在火狐,chrome和internet Explorer中运行它。该代码的目的是计算汽车每加仑燃料行驶的英里数。代码在我编辑continue变量并用proceed替换后运行。但是有谁能告诉我为什么totalbolater、totalMiles和avgTotal在程序运行时返回Nan值。
null
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>A computer program</title>
<script>
var miles;
var gasoline;
var gasolineValue;
var milesValue;
var avg;
var totalGasoline;
var totalMiles;
var avgTotal;
var proceed;
do
{
miles = window.prompt( "Enter number of miles driven","0" );
gasoline = window.prompt( "Enter number of gasoline used","0" );
milesValue = parseFloat( miles );
gasolineValue = parseFloat( gasoline );
avg=milesValue/gasolineValue;
document.writeln("<h3>Average number of miles/gasoline ="+ avg + "</h3>");
totalGasoline += gasolineValue;
totalMiles += milesValue;
proceed = window.prompt("Continue? Press 1 to continue, any other key to end", "1");
}
while (proceed == 1);
document.writeln("<h3>Total gasoline consumed:" + totalGasoline +"</h3>");
document.writeln("<h3>Total miles driven:" + totalMiles +"</h3>");
avgTotal=totalMiles/totalGasoline;
document.writeln("<h3>Total number of miles/gallon to this point:" + avgTotal + "</h3>");
</script>
</head>
<body></body>
</html>
null
将var continue的名称更改为其他名称(如_continue)