Script won't run need help please

hi, am trying to run a script from aptana but it won’t run, am just copying the code from the book no idea what is wrong if can help me please here is the script.

<!DOCTYPE html>
<html>
	<head>
		<title>the miles per gallon app</title>
		<script>
			var again = "y";
			do
			{
				var miles = prompt("enter miles driven");
				miles = parseFloat(miles);
				var gallons = prompt("enter gallons used");
				gallons = parseFloat(gallons);
				if (!NaN(miles) && miles > 0
				  && !isNaN(gallons) && gallons > 0)
				  {
				  	var mpg = miles / gallons;
				  	mpg = parseInt(mpg);
				  	alert("miles per gallon = " + mpg);
				  	}
				  	else
				  	{
				  		alert("one or both entries is invalid");
				  	}
				  	again = prompt("repeat entries?", "y");
				  }
				  while (again == "y");
				  
		</script>
	</head>
	
	<body>
		<main>
			Thanks for using the miles per galoon application!
		</main>

	</html>

Hi @hhz11, you’ll see the error in the console of the browser dev tools:

Uncaught TypeError: NaN is not a function

Hi @hhz11

<off-topic>
When you post code in the forum, you need to format it. To do so you can either select all the code and click the </> button, or type 3 backticks ``` on a separate line both before and after the code block.
</off-topic>

				if (!NaN(miles) && miles > 0
				  && !isNaN(gallons) && gallons > 0)

Should be

				if (!isNaN(miles) && miles > 0
				  && !isNaN(gallons) && gallons > 0)

HTH,

^ _ ^

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.