Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

JavaScript Program to Find Simple Interest



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

In this article we are given a data of principal, rate and time, our task is to write a JavaScript program to find simple interest. Users must be familiar with the formula to calculate the simple interest, arithemetic operators in javascript and javascript functions.

Formula:

Simple Intrest(SI): (p * r * t)/100
where,
p = Principal amount
r = Rate of interest
t = Time period

Example

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

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

Output:
SI = 1200

Steps to Find Simple Interest

We will be following below mentioned steps to find simple intrest.

  • First, we have declared three variables principal, rate, and time to store the principal amount, rate of interest, and time in years respectively.
  • Then we have defined a function interest() to find the simple intrest and passed p, r and t as arguments representing principal, rate and time respectively.
  • The function returns the intrest amount by calculating (p*r*t)/100. Simple intrest is calculated by calling the function intrest() by passing principal, rate and time variables as arguments, and is stored in the variable simpleIntrest.
  • The output is displayed in web console using console.log().

Example

Here is an example code implementing above mentioned steps to find simple intrest using JavaScript.

let principal=12000, rate=5, time=2;
function interest(p, r, t) {
    return (p*r*t)/100;
}
let simpleIntrest = interest(principal, rate, time);
console.log("Simple intrest: " +simpleIntrest); 
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.
Updated on: 2024-11-29T15:09:38+05:30

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements