How to Use math.fraction()

Hi! It says that math.fraction() isn’t defined. What does that mean? Did I do something wrong?

function math(onlyVar) {
  var first = math.pow((1 + (math.fraction(.06, onlyVar))), onlyVar)
  var second = first + 5000
  return second
}

math(1)

Why are you trying to make a function that has the same name as a built in library. That’s never good…

You have declared a function named math. You are attempting to reference a method named fraction that does not exist in your math function.

2 Likes

I looked up how to convert a set of numbers into fractions, and it said that to do that I’d need to use math.fraction()

But you are overwriting the built in math library by naming your function math. To put it another way, you cannot math. functions inside a function called math() because you changed what math refers to. Never name a function or class or variable the same name as a built in component.

1 Like

Thank you, I changed it but I’m still getting the error that math isn’t defined (line 2:30) Here’s the new code:

function equation(onlyVar) {
  var first = Math.pow((1 + (math.fraction(.06, onlyVar))), onlyVar)
  var second = first + 5000
  return second
}

equation(1)

What’s wrong is that math.fraction

Ok, getting closer. Now which version of the math library do you see that supports declaring a fraction like that, because I only see a version that supports a single argument (see math.js documentation).

Edit: Ah ha! Someone who speaks the ancient and arcane language of Javascript package management might be replying : )

how are you importing the math.js library to your code?

because I am thinking you are not, if you are getting that error

Could you post the link to where you read the tutorial? I found the math.js library. If this is the what you’re trying to use, then you need to bring in that library in order to use any of these extra methods like math.fraction() etc.

If you check out the Getting Started page, it will demonstrate basic usage.

2 Likes