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

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.