logo CodeStepByStep logo

investment

Language/Type: JavaScript parameters

Write a function named investment that takes three number parameters, initial, percent, and months, representing the initial amount of an investment, the interest rate percentage of that investment, and the length of the investment in months. Using the following compound interest formula, your function should calculate the profit of the investment for the given values:

PV * (1 + r)n = FV

Also report the overall "quality" of the investment as from the table below:

Profit Category
0 - 10% weak
10 - 50% medium
over 50% strong

Below is example output when calling investment(100.00, 0.03, 5), representing the investment of $100 with a 3% interest rate for 5 months:

Final amount = $115.93
Profit = $15.93 (16%)
medium

Use the console.log() function to print each line of output and n.toFixed(2) to get a string of a number n to the precision of two decimal points. For example, if n is 1.2345, n.toFixed(2) would return "1.23". Percentage values for an investment's profit should be rounded to the nearest whole integer.

Type your JavaScript solution code here:


This is a function exercise. Write a JavaScript function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.