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 JavaScript Basics (Retired) Working With Numbers Review Numbers and the Math Object

Laura Henneberry
Laura Henneberry
1,808 Points

Wouldn't the answer be Syntax Error, because .5 is not a whole number?

for console.log( parseInt( '.5 FTE' ));

2 Answers

Hi Laura,

parseInt will attempt to convert the string into an integer. If the first character can't be converted into a digit then it will return NaN - Not a Number

Since the period can't be converted to a digit it returns NaN.

If the string was '1.5 FTE' instead then it would return the number 1. The character 1 can be converted to a digit but the period can not so it stops right there.

Here's the mdn page on it if you'd like to read more: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

instead of using the parseInt() function, you might want to try using parseFloat(), .5 is a floating number and not an integer.

here is more on parseFloat()