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!

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

Killeon Patterson
Killeon Patterson
18,133 Points

what is the issue with my syntax for this challenge?

What is the correct syntax for this challenge?

1 Answer

On your choice.

It will return NaN (Not A Number)

width * numOfDivs === NaN
parseInt(width) * numOfDivs === 1900


parseFloat(width) * numOfDivs === 1900

will convert your string "190px" in to the number. So one and only thing you need to do is to convert string in to the number.

parseInt and parseFloat will not convert to the number the string in to the number if the string begin with a not a number value and it will throw away all numbers after the letter:

parseInt("a12345") === NaN
parseInt("!12345") === NaN
parseInt("123a!b45") === 123

There is a regular expression if you need to get all numbers but this task is about parseInt and parseFloat only.