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

ParseInt Challenge

I am putting in: var width = '190px'; var numOfDivs = 10; var width = parseInt(width); var totalWidth = width * numOfDivs;
The program keeps telling me " Bummer! Did you use the var keyword to create the totalWidth variable?" Am I doing something wrong?

2 Answers

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

Check the JavaScript console to see which line the error is coming from. I think you'll be surprised. The error is actually in line 3 ( var width = parseInt(width); ).

Remember that you don't need to use 'var' again when using the same variable. On line 4 of your code, you redeclare 'width' using 'var'. I would recommend eliminating altogether the need for another variable (line 3) and just make totalWidth equal to width (parsed as an int) times the number of Divs. (I tried explaining it without just writing the code for you).

EDIT: formatting

Thanks I got it after some trial and error with the knowledge you left me. Thank you.