Exponentiation (**)
let case200 = 200000, // loan amount
x = 1.07, //7% dividend
y5 = 5, y10 = 10, y15 = 15, y20 = 20, y25 = 25; //years
function dividendFunc5(value, years = y5) { //dividend function
if(years > 0)
return dividendFunc5(value*x, years - 1);
else
return value;
}
let case200k5y = dividendFunc5(case200), //5 years
case200k10y = case200k5y * x ** y5; // 10 years - amount of 5years * 7% dividend = total * total * total * total * total
console.log('200k in 10 years ' + case200k10y); // output 200k in 10 years 393430.2714579133