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

Christopher Johnson
Christopher Johnson
12,829 Points

Can I use "parseInt" anywhere in Javascript? Such as ( width * numOfDivs.parseInt(); ) ?

I am familiar with the syntax of C#. I noticed in the challenge that i couldn't find a way to use "parseInt" like this

var total = width * numOfDivs.parseInt();

I assume you understand what I am "attempting" to do, but is parseInt() a property that I can call on any string at any time?

2 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Christopher,

That's not how parseInt works in JS. Check out the MDN documentation for the function. It's not a method of a string (which is how you're using it). Rather, it's a function that takes a string as a parameter.

So if your numOfDivs variable is a string, you would call the function like this:

var total = width * parseInt(numOfDivs);

Edit I took a look at the challenge, and it looks like numOfDivs is an integer and width is the string you need to parse. In that case, your code should look like this:

var total = parseInt(width) * numOfDivs;
Christopher Johnson
Christopher Johnson
12,829 Points

Awesome. I looked at MDN, but something just must've slipped my sight. Pretty simple. Thank you for the answer.