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 trialUnsubscribed User
7,386 PointsUsing the 'parseInt' to get the 'totalWidth'. The message I keep getting is, Did you use the `var` keyword to create the
This is the Bummer message I keep getting.
Did you use the var
keyword to create the totalWidth
variable?
4 Answers
Krzysztof Kucharzyk
Front End Web Development Techdegree Student 4,005 PointsTry this:
var width = '190px';
var numOfDivs = 10;
var totalWidth = parseInt(width) * numOfDivs;
Unsubscribed User
7,386 Pointsvar width = '190px'; var num = parseInt(width); var numOfDivs = 10; var totalWidth = (width * numOfDivs);
Hi Chyno, This is the code I used.
Unsubscribed User
7,386 PointsAnd Krzysztof saves the day! If I may ask, where did you learn this? This pattern wasn't in the lesson/video nor in the teacher's notes.
Krzysztof Kucharzyk
Front End Web Development Techdegree Student 4,005 PointsWell sometime it's good to look for some methods/functions documentation to see what does it do before you use them. Like in this case read this MDN documentation about parseInt ;)
I took a look at this challenge to check if numOfDivs is a string variable or an integer and if width is a string you have to parse with.
So in this case if numOfDivs would be a string variable your function would look like:
var totalWidth = width * parseInt(numOfDivs);
But in this case it's integer and width is a string you have to parse so your code is like:
var totalWidth = parseInt(width) * numOfDivs;
Sandy Jones
7,854 PointsI keep getting the same message and here is what I did: var width = '190px'; var width = parseInt(width); var numOfDivs = 10; var totalWidth; var totalWidth = width * numOfDivs;
keep getting the message: Did you use the 'var' keyword to create the 'totalWidth' variable?
Chyno Deluxe
16,936 PointsChyno Deluxe
16,936 Pointsplease provide your code.