interest rate calculator html code -free html code -free html code with java script - Interest rate calculator free html code
Here is a code for simple and compounded rate calculator
<html>
<head>
<title>Interest Rate Calculator</title>
<style>
.container {
max-width: 400px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 4px;
}
.form-group {
margin-bottom: 10px;
}
.form-group label {
display: block;
font-weight: bold;
}
.form-group input {
width: 100%;
padding: 5px;
border: 1px solid #ccc;
border-radius: 4px;
}
.result {
margin-top: 20px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h2>Interest Rate Calculator</h2>
<div class="form-group">
<label>Principal Amount:</label>
<input id="principalAmount" placeholder="Principal amount" type="number" />
</div>
<div class="form-group">
<label>Interest Earned:</label>
<input id="interestEarned" placeholder="Interest earned" type="number" />
</div>
<div class="form-group">
<label>Time Period (in years):</label>
<input id="timePeriod" placeholder="Time period in years" type="number" />
</div>
<button onclick="calculateInterestRate()">Calculate Interest Rate</button>
<div class="result" id="interestRateResult"></div>
</div>
<script>
function calculateInterestRate() {
var principalAmount = parseFloat(document.getElementById('principalAmount').value);
var interestEarned = parseFloat(document.getElementById('interestEarned').value);
var timePeriod = parseInt(document.getElementById('timePeriod').value);
if (isNaN(principalAmount) || isNaN(interestEarned) || isNaN(timePeriod)) {
document.getElementById('interestRateResult').innerHTML = 'Please enter valid inputs.';
return;
}
var interestRate = (interestEarned / (principalAmount * timePeriod)) * 100;
interestRate = interestRate.toFixed(2);
document.getElementById('interestRateResult').innerHTML = 'Interest Rate: ' + interestRate + '%';
}
</script>
</body>
Comments
Post a Comment