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 trialDaniel McElroy
3,277 PointsShould this not be NaN since the code uses parseInt and not parseFloat? The number inside the string is a floating point
The number inside the string is a floating point. To be correct, should the code not be console.log(parseFloat('.5 FTE'));?
I've tested this and the original question returns an error.
2 Answers
LaVaughn Haynes
12,397 PointsIt should be NaN in the quiz.
With parseInt() and parseFloat() It's going to go from left to right and return as many characters as it can. If it can't return any characters then it's NaN.
Floating point numbers can start with a dot, so in your example with parseFloat() it will return .5 and throw away the ' FTE' part.
The quiz uses parseInt() though, and since the first character eliminates the possibility of returning an integer (an integer can't start with a dot) it just throws away the whole thing and you get NaN.
I don't know if that answers your question.
Daniel McElroy
3,277 PointsYes it does, thank you. I accidentally clicked the answer "Syntax Error" instead of "NaN". The quiz responded with something along the lines of "There is nothing wrong with this code." That threw me off since I would expect it to return an error (NaN, not syntax error.) It must have just been an error within the quiz.