Calculate Simple Interest

Program to calculate simple interest

BeginnerTopic: Basic Programs
Back

JavaScript Calculate Simple Interest Program

This program helps you to learn the fundamental structure and syntax of JavaScript programming.

Try This Code
// Formula: SI = (P × R × T) / 100
// Where: P = Principal, R = Rate, T = Time

let principal = 10000;
let rate = 5; // 5% per annum
let time = 2; // 2 years

let simpleInterest = (principal * rate * time) / 100;
let amount = principal + simpleInterest;

console.log("Principal: ₹" + principal);
console.log("Rate: " + rate + "% per annum");
console.log("Time: " + time + " years");
console.log("Simple Interest: ₹" + simpleInterest);
console.log("Total Amount: ₹" + amount);

// Function version
function calculateSimpleInterest(p, r, t) {
    let interest = (p * r * t) / 100;
    let total = p + interest;
    return {
        principal: p,
        rate: r,
        time: t,
        interest: interest,
        totalAmount: total
    };
}

let result = calculateSimpleInterest(5000, 8, 3);
console.log("\nUsing function:");
console.log(`Principal: ₹${result.principal}`);
console.log(`Interest: ₹${result.interest.toFixed(2)}`);
console.log(`Total: ₹${result.totalAmount.toFixed(2)}`);
Output
Principal: ₹10000
Rate: 5% per annum
Time: 2 years
Simple Interest: ₹1000
Total Amount: ₹11000

Using function:
Principal: ₹5000
Interest: ₹1200.00
Total: ₹6200.00

Understanding Calculate Simple Interest

This program calculates simple interest using the standard formula.

Simple Interest Formula

SI = (P × R × T) / 100

Where:

-

P

= Principal (initial amount)

-

R

= Rate of interest (percentage per year)

-

T

= Time period (in years)

Total Amount

Amount = Principal + Simple Interest

Example Calculation

For ₹10,000 at 5% for 2 years:

SI = (10000 × 5 × 2) / 100 = ₹1,000
Amount = 10,000 + 1,000 = ₹11,000

Key Concepts

1.

Principal

: The initial amount invested/borrowed

2.

Rate

: Interest rate as percentage (e.g., 5 means 5%)

3.

Time

: Duration in years

4.

Interest

: The extra amount earned/paid

5.

Amount

: Principal + Interest

Function Approach

Creating a reusable function that returns an object:

function calculateSimpleInterest(p, r, t) {
    let interest = (p * r * t) / 100;
        principal: p,
        interest: interest,
        totalAmount: p + interest
    };
}
    return {

Benefits:

Reusable code
Returns structured data
Easy to test
Clear calculation logic

Real-world Applications

Bank savings accounts
Loan calculations
Investment planning
Financial planning tools

Note:

Simple interest is different from compound interest, which calculates interest on interest!

Let us now understand every line and the components of the above program.

Note: To write and run JavaScript programs, you need to set up the local environment on your computer. Refer to the complete article Setting up JavaScript Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your JavaScript programs.

Table of Contents