Write two functions with these headers: function doFV() function computeFutureValue(principal, annualRate, years, periodsPerYear) The first function (doFV) takes no parameters is called from the onclick attribute gets input from the user calls the computeFutureValue function displays the result to the user

Respuesta :

Answer:

  1. function doFV(){
  2.    let p = Number(prompt("Enter principal amount: "));
  3.    let a = Number(prompt("Enter annual rate: "));
  4.    let y = Number(prompt("Enter number of years: "));
  5.    let n = Number(prompt("Enter number of periods per year: "))
  6.    computeFutureValue(p, a, y, n);
  7. }
  8. function computeFutureValue(principal, annualRate, years, periodsPerYear){
  9.    let amount = principal * Math.exp((1 + annualRate/ periodsPerYear), n*y);
  10.    console.log(amount);
  11. }

Explanation:

The solution code is written in JavaScript.

Firstly create function doFv that takes no parameter (Line 1). Use prompt method to get user input for principal amount, annual rate, number of years and number of periods per year (Line 2 -5). This is also important to use Number function to convert the input from string to numerical. After receiving user input, call the function computeFutureValue by passing the four user inputs as arguments (Line 7).

In the function computeFutureValue, apply compound interest formula to calculate the amount to be paid (Line 12). And use console.log to display the amount to terminal (Line 13).