• Theory
  • Theory

Eighth program: “Money makes money”

You’re ready to write one more program for the boss. He liked saving air miles and now he wants to save money for new lines of business. Naturally, went to a bank, found out about all the terms and conditions, and is now asking you to create a program for calculating the deposit. Here is the technical assignment:

Meow! I need to calculate how much money I will make on deposits with different terms and conditions. Design the program as calculateDeposit function with four parameters:

  1. Initial amount of the deposit;
  2. Interest per annum (number from 0 to 100);
  3. Term of deposit in months;
  4. With capitalization of interest or not (flag with a Boolean value).

The function must return the total amount of the deposit rounded to dollars using Math.round(). Use any parameter names.

If we have a simple deposit, the annual interest is divided by 12 and multiplied by the term of the deposit, and then the initial amount increases by the calculated interest.

Calculating a deposit with capitalization is more difficult: every month the annual interest accrued per month is added to the deposit amount (do not forget to divide the interest by 12), and the interest for the next month is calculated from the increased amount of the deposit.

If you are having trouble calculating interest on deposits, check out the hint.

Investing 1000 dollars at 8% per annum for 3 months.

If it’s a simple deposit, the total amount will be:

// Total interest
(0.08 / 12) * 3 * 1000 = 20 dollars
// Total deposit amount
1000 + 20 = 1020 dollars

If it’s a deposit with capitalization, the total amount will be:

// Amount after the first month
1000 + (0.08 / 12) * 1000 = 1007 dollars
// Amount after the second month
1007 + (0.08 / 12) * 1007 = 1014 dollars
// Amount after the third month (final amount)
1014 + (0.08 / 12) * 1014 = 1021 dollars

When you are done, press Hey boss, here’s your program!, and Muffin will come by to test it. Just don’t call Muffin for silly little things! The boss can get mad!

  • index.html
HTML
HTML

You’ve gone to a different page

Click inside the mini-browser to shift the focus onto this window.

100%
Granny Muffin

Easy there, pal!

To access the Functions challenges in the JavaScript programming, you need to sign up and subscribe first.