Counter that starts fast and ends slower I am trying to make a counter in javascript that counts up from 0 to a variable target number. There is also a time delay between each "tick" that gets slower and slower. So the initial count is fast and over time gets slower.
Now, the length of time it takes to get from 0 to the target variable number is also variable. 
How do I make sure that the entire count up process only takes the inputted length of time?
So start number: 0 (int)
Target number: variable (int)
Time of last tick: variable (eg 99(int) to 100(int)) (ms)
Time the entire process takes(ms) (eg. 5000)
And the ticks between each increment gets slower. Start millisecond is 0, last millisecond is as inputted
 A: Here's how to formalize your requirement. The delay between two ticks is a function $d$ from $\mathbb{N}$ to $\mathbb{R}^+$ which maps each integer $i$ to the delay between $i$ and $i+1$. If you let your counter run up to the integer $n$, the total delay is thus $$
  D(n) = \sum_{i=0}^{n-1} d(i) = d(0)+d(1)+\ldots+d(n-1)\text{.}
$$
Now say you want to count up to $n$ and you want that to take time $t$. You can simply scale the individual delays by $\frac{t}{D(n)}$, because you then get $$
  \sum_{i=0}^{n-1} \frac{t}{D(n)}d(i) = \frac{t}{D(n)}D(n) = t
$$
for the total time.
So all you have to do is pick a function $d$. Since you want the timer to become progressively slower, you'll of course pick a function with $d(i) < d(i+1)$. There are lots of choices here, but one particularly convenient one is $$
  d(i) = 2^i \text{.}
$$ In that case you get $$
  D(n) = \sum_{i=0}^{n-1} d(i) = \sum_{i=0}^{n-1} 2^i = 2^n - 1 \text{.}
$$
If you want to reach number $n$ at time $t$, the delay between $i$ and $i+1$ would thus (per the scaling idea above) have to be $$
  \frac{t}{D(n)}d(i) = t\frac{2^i}{2^n-1}\text{.}
$$
A: If I understand you correctly, the idea is to e.g. count to 100 over 60 seconds by updating a counter at apparently randomly chosen times.
This is straightforward; when an update is called after $t$ seconds, set the counter to $t/60\times 100$.
If you're just given the delays $D$ each time, and they're reasonably precise, just add $D/60\times 100$ each time.
If I've misunderstood, sorry, let me know.
