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

Eliot Ostling
Eliot Ostling
9,599 Points

JS: ParseInt question

var width = '190px';

var Width = parseInt(width); var numOfDivs = 10;

var totalWidth = Width * numOfDivs;

For this problem I am getting an error message telling me that I need to use 'var' to create totalWidth. However, I indeed have. I have also parsed var width: and I still am not getting my desired output. Thank you for any advice.

app.js
var width = '190px';

var Width = parseInt(width);
var numOfDivs = 10;

var totalWidth = Width * numOfDivs; 
index.html
<!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>

3 Answers

Christopher is correct! in this challenge you only need to use the parseInt() method in the new var totalWidth. you are really close on this one, but you only want the value to be a number in the new var totalWidth, not outside of it, because you might still want the string value, i.e. if there is a prompt function where someone have to input that info. you can't input a number, its value is a string. I hope this helps.

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

oh and just keep a look out for capitalizations of vars. the width var inside of totalWidth was capitalized.

Christopher van Ruitenbeek
Christopher van Ruitenbeek
13,705 Points
var totalWidth = parseInt(width);

Maybe you literally need to add a variable called totalWidth.

Eliot Ostling
Eliot Ostling
9,599 Points

Thanks you guys! I can see where I made my mistake. Thanks again Chris & Jacob! Definitely cleared up this part of the lecture/code.