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 trialAgan Murali
Courses Plus Student 893 Points"isNaN" is not a best suit for this program.
When you parse an argument like this "isNaN("1000", 2000)" this will return "false", because it's not checking what type it is. But I used this as a condition in order to solve that problem,
typeof(lower) === 'number' && typeof(upper) === 'number'
is it ok or does it have any best way to do.
2 Answers
Bernadette Guevarra
16,295 PointsisNaN stands for "is Not a Number", so it's like this, is ("1000") not a number? False, since js interprets this number in the string as a number (as long as it's only numbers inside the string, no spaces or other characters). Is ("a1000") not a number? True, since js interprets this alphanumeric string as a string. I played on the console in the developer tool a bit to see various results with isNaN, and it's quite helpful.
Andy Birchwood
3,703 PointsAs I was trying the challenge, this confused me, because I used a number in the string to test isNan would return true and it didn't. It also made a calculation using the string as a parameter, but I'm not sure how...
babasariffodeen
6,475 PointsHi Andy,
Just read your comment and wanted to clarify according to how I understand isNAN to work.
You mentioned you "used a number in the string to test isNan would return true and it didn't".
isNAN would return true if you parse something that is not a number.
So isNAN("a55") would be true because a55 is truly not a number. However, isNAN(60) would be false because it would be false to say that 60 is not a number.
Hope that helps.