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!

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


Numbers - The Math Operator (Code Challenge)

Hey guys,

I am really struggling with Math Operator (https://teamtreehouse.com/library/the-math-object) code challenge.

Here's the question

Create a variable named "circumference" and assign the correct value to it by using the "diameter" variable and Math.PI. See the comment in the script for more information.

I'm definitely not a numbers guy and I'm actually finding this code challenge quite frustrating, and it is putting a sour taste in my mouth towards JavaScript.

Any advice or code snippets would be greatly appreciated!

Many thanks

Stu :)

4 Answers

Hello Cowley,

Do not get frustrated. Keep calm my friend. Math.PI is a method that stores the number pi(3.14.......). And the diameter has already been created in the challenge. The formula for Circumference is:

diameter x PI

And so we use this formula to formulate our code. Like so:

var circumference = diameter * Math.PI;

Hope this helped. :)

Hey Guled A (sweet profile pic btw)

Thank you very much for your help and it worked a real treat. I get it now, it's amazing what an awesome community of fellow Treehousers and a very strong coffee will do!

Thanks again for your prompt help!

Stu :D

No problem. :)

  • 1

I learnt more from your example and detail than just pasting the answer. Sometimes no-one likes math!

scott duke
scott duke
5,033 Points

Wow.! I was trying

var circumference = diameter * Math.PI();

Javascript var circumference = Math.PI(diameter)```

Because diameter is a floating point number.
started getting scared, when I tried that, and it did not work. I finally passed because of your answer, but I need to keep going over this and also dive into bookmarks to make sure I totally get this. Don't feel confident, yet. I don't know if I would have thought to remove the parenthesis from the end of the constant Math.PI  :-(   */

How did you know to not use the parenthesis? I need to think different, if I am going to really get this.I apologize in advance for any errors in my markdown... I'm so tired. I just wanted to complete this before I even attempted sleep.  lol
[edit] I can't even get markdown working. 

Math.PI holds the value pie. If you put parenthesis next to it, you would be making it call a function (which does not exist). Also, in the exercise there was a comment below the practice area in which had the method without any parenthesis. It is ok to miss a few things at times, that is what practice is for. Do not ever feel disappointed, tell yourself "I got this!", and make an effort.

          Approximately 3.14159. Pi (?) is used
          to determine the circumference of a circle
          given its diameter by multiplying the diameter
          by ?. Geometery refresher: the circumference
          of a circle is the distance around the outside
          edge. The diameter is the width of the circle.
scott duke
scott duke
5,033 Points

Thanks, Guled A! Plowing through, I gain a little bit of confidence each time. I love Treehouse and how much I am learning here!