javascript - How to add a recurring Interest rate onto a recurring and growing amount -


i trying add given percentage onto number repeatedly on few months has percentage added on previous month.

i.e, user defines 25% (this not set number of percent) add 25% onto amount invested start with, example:

customer invests £10,000, add 25% onto £10,000, equals £12,500. and then following month add 25% onto £12,500 month before, should equal £15,625.

it should case of simple maths, yet cannot figure out using javascript. keep getting value of £15,000, , cannot work out how store given percentage in variable , add percentage onto total amount.

here code.

// set values...  	 num = prompt("enter percentage using decimal number...");  	 interestrate = num*100;  	 startcash = 10000;  	 total = startcash*interestrate/100+startcash;  	 month = 1;  	   	 // inputting text...  	 starttext = "starting money: £";  	 inttext = "interest earned: ";  	 totaltext = "total amount: £";  	 monthtext = "month: ";  	   	 displaystart = starttext + startcash + "\n";  	 dispint = inttext + interestrate + "\n";  	 disptotal = totaltext + total + "\n";  	 dispmonth = monthtext + month + "\n";      	 dispvalue = displaystart + dispint + disptotal + dispmonth;  	       	 console.log (dispvalue);    	 addint = total + interestrate*100;    	 console.log (addint);

you try approach this:

var interestrate = .25;  var startcash = 10000;  var total=startcash;  for(var monthcount=1; monthcount<13;monthcount++){      //this line takes previous value of total , gets percentage of interest     //it re-assigned same variable     total += total*interestrate;       console.log('month :', monthcount);     console.log('total :', total);  } 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -