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 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,268 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,268 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 :)