JavaScript
// 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
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
-
Principal: The initial amount invested/borrowed
-
Rate: Interest rate as percentage (e.g., 5 means 5%)
-
Time: Duration in years
-
Interest: The extra amount earned/paid
-
Amount: Principal + Interest
Function Approach
Creating a reusable function that returns an object:
javascriptfunction calculateSimpleInterest(p, r, t) { let interest = (p * r * t) / 100; return { principal: p, interest: interest, totalAmount: p + interest }; }
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