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

Yusuf Salaam
Yusuf Salaam
1,748 Points

I need help

How do i complete the first challenge of parsing numbers

2 Answers

Stone Preston
Stone Preston
42,016 Points

the challenge states: A variable named "boxWidth" already exists with a value of "640px". Create a new variable named "numWidth" and use the "parseInt" method to extract the numeric value from boxWidth's string value.

so first you need to create a new variable and assign it the value of calling the parseInt function and passing it the boxWidth variable as an argument and 10 as the other argument for the radix.

hint: you can call the parseInt function like this:

parseInt(someString, 10)

where someString is a variable that you want to parse.

Here is the documentation on the parseInt function

Yusuf Salaam
Yusuf Salaam
1,748 Points

var numWidth = parseInt("640px",10); I entered this but it keeps saying im wrong. What am I missing?