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

parseInt not working what am i doing wrong?

var boxWidth = "640px"; var boxHeight = "480px";

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

3 Answers

Richard Duncan
Richard Duncan
5,568 Points

You have " wrapping your variable name, so parseInt is literally being called on a string with the value of "boxWidth" rather than the variable boxwidth that contains the string value "640px".

Also, you need a comma separating your arguments e.g.

parseInt(boxWidth, 10);

OK Thanks that worked

Richard Duncan
Richard Duncan
5,568 Points

Fancy marking it as correct so that it might help someone in the future? :)

Done thanks a lot Richard.

Richard Duncan
Richard Duncan
5,568 Points

No probs man glad I could help.