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 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
seal-mask
.a{fill-rule:evenodd;}techdegree
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?