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 trialDeMarco Spears
1,342 PointsThe value of `totalWidth` is NaN, but it should be 1900. Did you multiply the width by the `numOfDivs` variable?
someone help
var width = '190px';
var numOfDivs = 10;
var totalWidth = width * numOfDivs;
parseInt(width);
document.write(totalWidth);
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, DeMarco Spears! First, you're doing great. You've clearly understood that you need to parse that string into an integer to use it. The problem comes in the order here. You call parseInt
on width after you've already tried to use it. The easiest way to fix this is to parse it on the same line where you're doing the calculation:
var totalWidth = parseInt(width) * numOfDivs;
This will turn that string "190px" into just a plain old number 190
so that you can then multiply it.
Hope this helps!
DeMarco Spears
1,342 PointsThanks!!!! You rock.