• Theory
  • Theory

Ninth program: “The Eternal Question”

The program for calculating deposits showed two things:

  1. When other conditions are the same, a deposit with a capitalization of interest is more profitable than a deposit with simple interest.
  2. Bankers might me many things, but they are not fools. Therefore, they offer different interest for different types of deposits.

That’s why choosing the most profitable type of deposit is not so easy. Fortunately, this task can be automated and deposits with different conditions can be compared. Anyway, here is a standard technical assignment:

Meow! I need a program to compare types of deposits. I specify deposit parameters in variables:

  1. initialAmount is the initial deposit amount,
  2. depositDuration is the deposit term in months,
  3. simplePercent is interest rate for a deposit with simple interest,
  4. complexPercent is the interest rate for a deposit with capitalization of interest.

The program should calculate the final deposit amount for deposits with simple and capitalized interest, and then save the recommendations in two variables:

  1. recommendedType is the recommended type of deposit. Assign 'simple' string to this variable if you recommend a simple deposit and 'compound' string if a deposit with a capitalization of interest is more profitable.
  2. finalAmount is the final deposit amount.

The task may seem complicated and time-consuming, but it is not the case, because you have already written half of the solution in the previous task. Your function for calculating interest has already been written and tested, which means that it works as it is supposed to. All we have left to do is copy it from the previous task, call it using the right arguments (for a deposit with simple interest and a deposit with capitalization), compare the results and determine which one is more profitable.

Long live code re-use!

This task can also be solved without using functions, because Muffin will keep changing the values ​​of variables and testing your solution, just like he did in other chapters. But since you already have a tested and proven function, you can use it to speed up the solution. Then you will have to call this function yourself and transfer into it values ​​from input variables. You already know how to do it.

When everything is ready, call the Boss, as always, by clicking the Hey boss, here’s your program! button.

  • 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.