answersLogoWhite

0


Best Answer

You take the formula for simple interest, and create a function based off of it.

The formula to generate simple interest is:

Interest = Principal * Rate * Time

In this case "time" refers to the number of periods for which interest will be applied.

In most cases you're going to want to solve this equation for interest. So, you write a JavaScript function that will do the math for you. The function should take Principal, Rate, and Time as parameters, and return Interest.

function calculateSI ( p, r, t ){

//You want to check that p, r, and t are appropriate values and//types. I'll skip that here for brevityreturn p*r*t;

}

That's all there is to it. To call the function, you'd pass in values in the proper order, of define them in the call. Then you capture the returned value with a variable like so:

var simpleInterest = calculateSI ( 5000, 0.12, 64 );

//simpleInterest would now hold the value of "38400."

I've gone ahead and create a JSFiddle example for you in which I set up a form to deal with acquiring and displaying the values. That version also shows how to write a single function to solve for any of the missing variables. (See related link.)

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you calculate simple interest in javascript?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Draw a flow chart to calculate simple interest with 10 percent rate if time is greater than 2 yrs otherwise calculate simple interest with 5 percent?

Draw a flow chart to calculate simple interest with 10% rate if time is greater than 2 yrs otherwise calculate simple interest with 5%.


How do you calculate simple interest earned?

simple interest = principle (money) times the rate times the time


How do banks calculate simple interest?

The simple interest, on an amount Y, at rate r% per year, for t years is I = Y*(r/100)*t But bank interest is always compounded, never simple.


Which of these steps should be performed first to calculate simple interest?

change % to decimal


How do I Calculate interest on 100000?

To calculate an interest (as money), multiply the capital, times the interest rate (divided by 100, if it is expressed in percent), times the number of periods. The above assumes simple interest; compound interest is a bit more complicated.


If you have an account with an annual simple interest rate of 2.1 percent. You have a principle of 450.00. calculate your interest and your principle for two years?

18.90currency as an interest..


Pseudocode and flowchart for simple interest calculation?

begin enter Principal amount(Input) enter interest rate(Input) calculate simple interest(Computation/Processing) Display/Show/Print Give sound Simple Interest(output) end By Tomas Naxweka(Namibia)


Calculate the simple interest on a loan with a principal of 6.000 an interest rate of 7.39 percent and a term of four years?

1,773.60


Calculate the simple interest you would receive in five years on a saving account that earns 7.5 annual interest Your beginning balance is 1236.59?

The simple interest over a period of five years is $463.70


which of the following is not to calculate simple interest?

Another answer from Apex is... compounding frequency


What is the algorithm and flowchart to calculate the simple interest for 5 customers?

algorithms is language independent


Calculate the simple interest on the amount of 567.23 at 5 percent for two years?

56.72