JavaScript Program to find simple interest


We will use the formula for simple interest to calculate the interest for a given principal amount, rate of interest, and time period. Simple interest is calculated as the product of the principal amount, rate of interest, and time period. This formula makes it easy for us to find the interest amount without having to calculate the compound interest.

In our JavaScript program, we will take input from the user for the principal amount, rate of interest, and time period, and then use the formula to calculate the simple interest. We will then display the result to the user.

By using this JavaScript program, we will be able to calculate simple interest quickly and easily for different sets of inputs, making it convenient for us to analyze and compare investment options.

Approach

Simple interest is calculated by multiplying the principal amount, interest rate and time period.

  • Take the inputs for principal amount (p), interest rate (r) and time period (t).

  • Calculate the interest by using the formula "p * r * t".

  • Add the interest to the principal amount.

  • Store the result in a variable.

  • Display the result.

  • End the program.

Example

Here is a complete JavaScript program to calculate simple interest, along with explanations of the code −

// Define the variables to store the principal, rate of interest, and time
var p = 1000; // Principal amount
var r = 0.05; // Rate of interest
var t = 2;    // Time in years

// Calculate the interest using the formula
// Simple Interest = (principal * rate * time) / 100
var interest = (p * r * t) / 100;

// Display the result
console.log("Simple Interest: " + interest);

Explanation

  • We first declare three variables p, r, and t to store the principal amount, rate of interest, and time in years, respectively.

  • Next, we use the formula for simple interest, (principal * rate * time) / 100, to calculate the interest and store it in a variable interest.

  • Finally, we use the console.log() method to display the result on the console.

Updated on: 15-Mar-2023

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements