PDA

View Full Version : isNan w/ Array.



LearningCoder
05-02-2011, 06:56 AM
Hi there, I am currently messing around with a code that I made previously. It's a very simple code, and what I am looking to do is access the array elements (which do a calculation). I can access the elements fine and display the results, but I am looking to 'validate' the prompt box using 'isNan' but since I have changed my code, only the prompt box shows but no alert message.

Here is my code:


<script type="text/javascript">

var degFahren = prompt("Enter the degrees in Fahrenheit", 50);
var degCent;
var myArray = new Array();

myArray[0] = 0;
myArray[1] = 1;
myArray[2] = 2;
myArray[3] = 3;
myArray[4] = 4;
myArray[5] = 5;
myArray[6] = 6;
myArray[7] = 7;
myArray[8] = 9;
myArray[9] = 32;

degCent = myArray[5] / myArray[8] * (degFahren - myArray[9]);


while (isNan(degFahren) == true)
{
alert("You did not enter a number");
}
while (isNan(degFahren) == false)
{
alert("\xB0" + degFahren + " Fahrenheit is \xB0" + degCent + " Centigrade.");
}



</script>

If anyone could please give me any information I will be very thankful, it's been racking my brains all night!

Thank you in advance. :)

jscheuer1
05-02-2011, 07:17 AM
There could be other problems but there is no isNan() method. It's isNaN()