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 Basics (Retired) Working With Numbers Numbers and Strings

Using the 'parseInt' to get the 'totalWidth'. The message I keep getting is, Did you use the `var` keyword to create the

This is the Bummer message I keep getting. Did you use the var keyword to create the totalWidth variable?

please provide your code.

4 Answers

var width = '190px'; var num = parseInt(width); var numOfDivs = 10; var totalWidth = (width * numOfDivs);

Hi Chyno, This is the code I used.

And Krzysztof saves the day! If I may ask, where did you learn this? This pattern wasn't in the lesson/video nor in the teacher's notes.

Krzysztof Kucharzyk
Krzysztof Kucharzyk
Front End Web Development Techdegree Student 4,005 Points

Well sometime it's good to look for some methods/functions documentation to see what does it do before you use them. Like in this case read this MDN documentation about parseInt ;)

I took a look at this challenge to check if numOfDivs is a string variable or an integer and if width is a string you have to parse with.

So in this case if numOfDivs would be a string variable your function would look like:

var totalWidth = width * parseInt(numOfDivs);

But in this case it's integer and width is a string you have to parse so your code is like:

var totalWidth = parseInt(width) * numOfDivs;

I keep getting the same message and here is what I did: var width = '190px'; var width = parseInt(width); var numOfDivs = 10; var totalWidth; var totalWidth = width * numOfDivs;

keep getting the message: Did you use the 'var' keyword to create the 'totalWidth' variable?