Math problem
I have the following function:
function getLevel(points)
{
var level = -1 + Math.sqrt(4 + points/20);
// Round down to nearest level
return Math.floor(level);
}
The above function calculates the player's level based on their points, my problem is I need a function like this to calculate the points needed for a given level.
+2
a source to share
5 answers
Should be pretty easy, just solve for points:
level = -1 + Math.sqrt(4 + points / 20)
level + 1 = Math.sqrt(4 + points / 20)
Math.pow(level + 1, 2) = 4 + points / 20
Math.pow(level + 1, 2) - 4 = points / 20
20 * (Math.pow(level + 1, 2) - 4) = points
So:
points = 20 * (Math.pow(level + 1, 2) - 4)
+2
a source to share