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 trialChristina Freyhult
Front End Web Development Techdegree Student 9,565 PointsStuck on 'var' definition, but am getting the correct answer from math challenge
In the code challenge: Numbers and strings 2, I get stuck and have no idea why.
The challenge is to convert a string into a number, then multiply it to another number. Both of these numbers are defined as variables. My code:
var width = '190px'; var numOfDivs = 10; var numWidth = parseInt(width); var totalWidth = numWidth * numOfDivs;
I have tested to print out both "numWidth" and "totalWidth" which give me 190 and 1900. So the numbers are working out. But I keep getting the error of " Bummer! Did you use the var
keyword to create the totalWidth
variable?"
I have reloaded the page, closed the window and loaded the challenge again, but with the same result. Any ideas on what I'm doing wrong? Thanks!
2 Answers
Steven Parker
231,008 PointsYour code is perfectly legitimate, but the challenge is being picky.
Code-wise, there's nothing wrong with your solution, but the challenge is apparently expecting you to use the function to convert the string in the same statement as you make the final assignment. The creation of the intermediate value seems to be confusing it. Try re-writing your answer without the extra variable and pass the challenge.
You might also report the failure of the challenge to accept your initial solution as a bug using the Support page.
Christina Freyhult
Front End Web Development Techdegree Student 9,565 PointsSkipping the intermediate step was the solution, I passed the challenge. Thanks!