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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 1 Solution

amz baz
amz baz
2,053 Points

why isn't 3.14 recognised as a number?

I want to get the value of PI as answer of 3.14 but when I answer all three of my questions right i get 2/3 score. So my question is why is 3.14 not recognised as a number?

2 Answers

Emmanuel Molina
Emmanuel Molina
9,267 Points

We need more info to anwser but I guess you captured the user's answer as a text input and don't parse it into a number before testing it.

use Number() before the test and don't forget to think as NaN as a possible result

amz baz
amz baz
2,053 Points

Hi, I did use parseInt before the prompt command like below: response = parseInt(prompt(question));

I'll try the number() and NaN. Thanks.

Emmanuel Molina
Emmanuel Molina
9,267 Points

Ok I see your mistake

```parseInt() return an integrer => open console > parseInt(3.14) > 3

parseFloat() will return a decimal => open console parseFloat(3.14) > 3.14

Number() will also return a decimal => open console Number(3.14) > 3.14```

amz baz
amz baz
2,053 Points

I completely forgot about praseFloat thanks for the reminder :)