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 trialStu Cowley
26,287 PointsParsing 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
Victor Arellano
12,045 PointsHello Stu.
You gotta pass the variable as an argument to the parseInt function:
var numWidth = parseInt(boxWidth, 10);
Agon Bina
Courses Plus Student 1,308 PointsI 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)
Stu Cowley
26,287 PointsHey 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 :)
Stu Cowley
26,287 PointsHello 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