title: Javascript interest calculator, how to return values with two different rates
body: <p>I have this earning calculator function</p>
  
  <pre><code>EarningsCalculator.prototype.computeEarning = function (rate, investedValue) {
  
      var earnings = {};
      var currentState = investedValue;
      for (var i = 0; i &lt;= 5; i++) {
  
              earning=currentState*rate;
  
              currentState = currentState + earning;
  
          earnings[i] = currentState;
      }
  
      return earnings;
  }
  </code></pre>
  
  <p>It takes an "invested value" and based on a give rate, it calculates earning, which in this case is limited to 5 years with a for loop. What I need is to calculate <code>earnings[0]</code> at 1 year interval and <code>earnings[1]</code> through <code>earnings[4]</code> at a 5 year interval.</p>
  
  <p>So with Invested value of 1000 and interest rate of 10%, it returns the following output for 5 years</p>
  
  <pre><code>Year1  = 1100
  Year2  = 1210
  Year3  = 1331
  Year4  = 1464.1
  Year5  = 1610.51
  </code></pre>
  
  <p>What I want is this</p>
  
  <pre><code>Year1  = 1100
  Year5  = 1610.51
  Year10 = 2593.74246
  Year15 = 4177.248169
  Year20 = 6727.499949
  </code></pre>