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>
		<title>the miles per gallon app</title>
			var again = "y";
				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);
				  		alert("one or both entries is invalid");
				  	again = prompt("repeat entries?", "y");
				  while (again == "y");
			Thanks for using the miles per galoon application!


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

Uncaught TypeError: NaN is not a function

Hi @hhz11

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.

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

Should be

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


^ _ ^

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