Home > other >  Cannot read properties of undefined (reading 'toString')
Cannot read properties of undefined (reading 'toString')

Time:12-08

I'm currently trying to parse anonymous functions and am currently getting the error as per the title. I've tested a few things, and the core math works, but there's an issue with parsing the information. Any help is appreciated.

In this instance, manaCost = 10 and manaLevel = 0

if(manaLevel>=1){
manaCost = increase(5,manaCost,1.17,manaLevel);
} else {
manaCost = increase(5,manaCost,1.17,1);
}
function increase(n,b,r,k){
    b * (Math.pow(r,k)*((Math.pow(r,n)-1)/(r-1)));
}

The core math of

manaCost * (Math.pow(1.17,1)*((Math.pow(1.17,5)-1)/(1.17-1)))

functions.

CodePudding user response:

You need to return a value in your functions if you want to assign something to the return value of the function. Otherwise it returns undefined.

function increase(n,b,r,k){
    return b * (Math.pow(r,k)*((Math.pow(r,n)-1)/(r-1)));
}
  • Related