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 Foundations Numbers The Math Object

Nathan Begnaud
Nathan Begnaud
8,221 Points

Code 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

Hi Nathan,

Your code is correct. Where did you place it? It needs to be after the existing variable definitions.

Nathan Begnaud
Nathan Begnaud
8,221 Points

Thanks just had to put it after everything like you said.

You'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.

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Where 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).

Hi Craig,

If you click on the code challenge link in the right column you can see where it is defined.