Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Thanitsak Leuangsupornpong
Thanitsak Leuangsupornpong
7,490 Points

If we want to find the string we use QuoteMark,but what about number?

I mean, If there are a number so do ... ,but how to write in code 'there are number in...' I want to check that there are a number or not,same with parseInt() that check the number if there are dot or word it going to error or NaN

1 Answer

Mark VonGyer
Mark VonGyer
21,239 Points

I'm not quite sure what you mean, but...

parseInt(string) will only work if the int is the first part of the string. It will then only parse the int upto the first character that isn't a number.

If you want to check if the value entered is a number you can use NaN (which stands for Not A Number). This returns a boolean value.

Incidentally, if you use parseInt("10tentenententen") you will get the number 10.

if you parseInt("ten10tentententen") you will get NaN = not a number.

Thanitsak Leuangsupornpong
Thanitsak Leuangsupornpong
7,490 Points

i use NaN but it still not work, if(a===NaN){alert('Wrong')}

Mark VonGyer
Mark VonGyer
21,239 Points

You can't use it like that.

You would need to use the method to check the boolean value. if(isNaN(a))

NaN is a response code, but the value or a will not be NaN. Use the method and it will work :)

Thanitsak Leuangsupornpong
Thanitsak Leuangsupornpong
7,490 Points

Can you explain why there no equal sign ===, and how does the code do with, if(isNaN(a))