# Using NaN in an if statement

**URL:** <https://forum.kirupa.com/t/using-nan-in-an-if-statement/13673>\
**Category:** Uncategorized\
**Created:** [February 16, 2003, 7:19pm UTC](https://forum.kirupa.com/t/using-nan-in-an-if-statement/13673 "2003-02-16T19:19:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mojoNYC](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@mojoNYC](https://forum.kirupa.com/u/mojoNYC)\
**Post date:** [February 16, 2003, 7:19pm UTC](https://forum.kirupa.com/t/using-nan-in-an-if-statement/13673/1 "2003-02-16T19:19:35Z")

</div>

ive got an array of cards 2-10 plus jack, queen, king, ace and i’m pulling members from the array at random–in order to score it, i decided to check the first character of the string and see if it returns a number or not.  
if it’s a number, add the number to the score, but if it returns ‘NaN’ (not a number) then it will just add 10 to the score–so even tho NaN is defined as a variable in flash, somehow my if statement ‘char==NaN’ isn’t working…

```php

functionÊscoreCard(){
//get first member of string, check to see if its a number
ÊÊÊÊchar=randMember.charAt(0);
 ÊÊÊchar=Number(char);
ÊÊÊÊif(char==NaN){
ÊÊÊÊÊÊÊÊtrace("Hi");
ÊÊÊÊÊÊÊÊscore+=10;
ÊÊÊÊÊÊÊÊ}elseÊ//trace(char);
ÊÊÊÊÊÊÊtrace("Lo");
ÊÊÊÊÊÊÊÊscore+=char;
ÊÊÊÊ//trace(score);
}

```

does somebody have the goods on how to do this right?  
i’ve attached a fla of it in the thread titled ‘arrays??!!’  
thanks,  
-mojo

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 16, 2003, 7:22pm UTC](https://forum.kirupa.com/t/using-nan-in-an-if-statement/13673/2 "2003-02-16T19:22:41Z")

</div>

i should also say that it works right to add the 2-9 numbers to the score, and that it does return ‘NaN’ if its a high card, but it doesn’t evaluate true in the line ‘if(char==NaN)’

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 16, 2003, 7:35pm UTC](https://forum.kirupa.com/t/using-nan-in-an-if-statement/13673/3 "2003-02-16T19:35:50Z")

</div>

Try

```php
if (isNaN(char)) {
	trace("Hi");
	score += 10;
} else {
	trace("Lo");
	score += char;
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 16, 2003, 8:00pm UTC](https://forum.kirupa.com/t/using-nan-in-an-if-statement/13673/4 "2003-02-16T20:00:51Z")

</div>

right on!  
thanks for the tip(-:  
-mojo

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 16, 2003, 8:02pm UTC](https://forum.kirupa.com/t/using-nan-in-an-if-statement/13673/5 "2003-02-16T20:02:33Z")

</div>

No problem 🙂
