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 trialNathan Begnaud
8,221 PointsCode Not Working For Some Reason
My code, var circumference = diameter * Math.PI;
It says there's an error and I don't know why.
2 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Nathan,
Your code is correct. Where did you place it? It needs to be after the existing variable definitions.
Craig Dennis
Treehouse TeacherWhere do you define diameter? If it is undefined you will get a ReferenceError if it is a string you will got NaN (Not a number).
Jason Anello
Courses Plus Student 94,610 PointsHi Craig,
If you click on the code challenge link in the right column you can see where it is defined.
Nathan Begnaud
8,221 PointsNathan Begnaud
8,221 PointsThanks just had to put it after everything like you said.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsYou're welcome.
Yes, if you put it before then the
diameter
variable is not yet defined at that point and so you get an error when trying to use it in an expression.