Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

JS - Dividend calculator function

0 votes
5 views
added Jul 13 in Javascript by LC Marshal Lieutenant (14,830 points)

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

 

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...