Skip to main content

calculateProgress

The calculateProgress() function calculates the progress made towards a goal, given the current progress.

Parameters

ParameterTypeDescription
currentNumberThe current progress towards the goal.
goalNumberThe required progress towards the goal.

Returns

  • Number: The progress made towards the goal, as a percentage between 0 and 1.

Throws

  • Error: Will throw an error if the current or goal values are not numbers or are negative.

Example

const utils = require('utils-core.js');
const current = 345;
const required = 1000;
const progress = utils.math.calculateProgress(current, required);
console.log(progress);
//output: 0.34