I am seriously pulling my hair out over this. I am writing a compound interest calculator in HTML and JS. The calculations are completely off. I don't know where I went wrong, since I get no error message. My HTML code:
<label for="Start_amnt">Initial investment:</label>
<br>
<input type="number" id="Start_amnt" name="Start_amnt" STYLE="font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #FEFEFE; width:12em">
<br>
<label for="Percentage">Interest rate:</label>
<br>
<input type="number" id="Percentage" name="Percentage" STYLE="font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #FEFEFE; width:7em">%
<br>
<label>Time period</label>
<br>
<input placeholder="0" type="number" id="Period_Year" name="Period_Year" STYLE="font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #FEFEFE; width:5em"> <span>Years</span>
<input placeholder="0" type="number" id="Period_Month" name="Period_Month" STYLE="font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #FEFEFE; width:5em"> <span>Months</span>
<br>
<button type="submit" onclick="calculate(Start_amnt.value, Percentage.value, Period_Year.value*12 + Period_Month.value)"> Calculate </button>
My JS code
function calculate(P,r,months) {
for(i=0; i< months; i++){
cashBack = P * Math.pow( 1 + r/100, months)
P = cashBack
console.log(cashBack);
}
}