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

Parsing Numbers from Strings Code Challenge

Hey guys,

So I am left scratching my head on the Parsing Numbers From Strings Code Challenge.

In a nutshell I have absolutely no idea how to do this! Could someone please explain this to me in simple terms.

I have tried

var numWidth = parseInt(640, 10);

*Sorry having problems with the code block command :-*

I will re-watch the Parsing Numbers from Strings video till I understand this throughly

Thanking you in advanced

Stu :)

4 Answers

Hello Stu.

You gotta pass the variable as an argument to the parseInt function:

var numWidth = parseInt(boxWidth, 10);

I think parseInt takes a string as the first argument, and the base as the second.

So in your case, var numWidth = parseInt("640", 10); // meaning I want to parse the string "640" to an integer of numbers with base 10 (ie, 0, 1, 2, ... 9)

Hey Agon!

That has helped! I declare the string of "640" and the integer is 10, however I still get the same error which is

Sorry! That's not correct. A correct answer will use the form: var numVariable = parseInt(stringVariable, radix);

What does this error message mean!?

Stu :)

Hello Victor,

Once agin you have saved me loads of stress! This is the first code challenge since I first signed up in June that I have been completely stumped on.

Yes that worked perfectly and your explanation helped a greatly!!

Stu :D