Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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()