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 Foundations Numbers Parsing Numbers From Strings

hakan Gülay
hakan Gülay
8,489 Points

question

http://teamtreehouse.com/library/parsing-numbers-from-strings

ı really couldnt do this code. actually ı couldnt understand what he wants. can you please help me ?

ı tried these codes

var numWidth=parseInt("boxWidth",10);
var numWidth=parseInt("640px",10);

6 Answers

Martin Mekhaiel
Martin Mekhaiel
14,297 Points

remove the double quotes from boxWidth. dont make "boxWidth" make boxWidth.

regards :)

James Barnett
James Barnett
39,199 Points

hakan Gülay -

To follow up on Martin Mekhaiel's excellent answer, the reason boxWidth works and "boxWidth" doesn't is that boxWidth is a variable and "boxWidth" is a string.


It's key to understand the difference when writing JavaScript, let us know here in this thread if you are still a little vague about why the Martin Mekhaiel's code works.

Erik McClintock
Erik McClintock
45,783 Points

Hakan,

Can you post the code that you tried, if any?

The code challenge is asking you to use the parseInt method to take the string values inside of the boxWidth and boxHeight variables and turn them into integers.

If you can post your code, I would be happy to help point you in the right direction!

Erik

Martin Mekhaiel
Martin Mekhaiel
14,297 Points
var numWidth = parseInt(boxWidth, 10);

this should work, it gets the integer from the string "640px" => parse int will return 640

regards.

hakan Gülay
hakan Gülay
8,489 Points

var numWidth=parseInt("boxWidth",10);

and var numWidth=parseInt("640px",10); ı tried these codes

hakan Gülay
hakan Gülay
8,489 Points

thank you a lot :)