The following function to calculate 5% dividend of RM100 for 5 years
function dividendFunc(value, years = 5) {
if(years > 0)
return dividendFunc(value*1.05, years - 1);
else
return value;
}
alert('RM' + dividendFunc(100)); //function output
alert('RM' + 100 * 1.05 * 1.05 * 1.05 * 1.05 * 1.05); //to check whether output are correct