JavaScript Program to Find Simple Interest

To find simple interest in JavaScript, we calculate the product of principal amount, rate of interest (%), and time period. Simple interest is a quick and easy method to find the interest charge or extra amount paid by a borrower to a lender on a certain amount of principal within a time period.

In this article, we are given data for principal, rate, and time. Our task is to write a JavaScript program to find simple interest. Users should be familiar with the formula to calculate simple interest, arithmetic operators in JavaScript, and JavaScript functions.

Formula

Simple Interest (SI): (p * r * t) / 100

where,
p = Principal amount
r = Rate of interest (%)
t = Time period (years)

Example Calculation

Input:
p = 12000, r = 5, t = 2

SI = (p * r * t) / 100
SI = (12000 * 5 * 2) / 100
SI = 120000 / 100

Output:
SI = 1200

Steps to Find Simple Interest

We will follow these steps to find simple interest:

  • Declare three variables principal, rate, and time to store the principal amount, rate of interest, and time in years respectively.
  • Define a function interest() to calculate simple interest and pass p, r, and t as parameters representing principal, rate, and time.
  • The function returns the interest amount by calculating (p * r * t) / 100.
  • Call the function and store the result in a variable.
  • Display the output using console.log().

Implementation

Here is the JavaScript code to calculate simple interest:

let principal = 12000, rate = 5, time = 2;

function interest(p, r, t) {
    return (p * r * t) / 100;
}

let simpleInterest = interest(principal, rate, time);
console.log("Simple Interest: " + simpleInterest);
Simple Interest: 1200

Alternative Method with User Input

Here's how you can create a more flexible function that accepts different values:

function calculateSimpleInterest(principal, rate, time) {
    const interest = (principal * rate * time) / 100;
    return interest;
}

// Test with different values
console.log("Case 1:", calculateSimpleInterest(10000, 8, 3));
console.log("Case 2:", calculateSimpleInterest(5000, 12, 1.5));
console.log("Case 3:", calculateSimpleInterest(25000, 6.5, 4));
Case 1: 2400
Case 2: 900
Case 3: 6500

Complete Example with Details

function simpleInterestCalculator(p, r, t) {
    const interest = (p * r * t) / 100;
    const totalAmount = p + interest;
    
    console.log("Principal Amount: $" + p);
    console.log("Rate of Interest: " + r + "%");
    console.log("Time Period: " + t + " years");
    console.log("Simple Interest: $" + interest);
    console.log("Total Amount: $" + totalAmount);
    
    return interest;
}

// Calculate simple interest
simpleInterestCalculator(15000, 7, 3);
Principal Amount: $15000
Rate of Interest: 7%
Time Period: 3 years
Simple Interest: $3150
Total Amount: $18150
Practice and learn from a wide range of JavaScript examples, including event handling, form validation, and advanced techniques. Interactive code snippets for hands-on learning.

Conclusion

Calculating simple interest in JavaScript is straightforward using the formula (p × r × t) / 100. This method is useful for financial calculations and demonstrates basic arithmetic operations and function usage in JavaScript.

Updated on: 2026-03-15T23:19:01+05:30

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements