Estimated Earnings
Your total CD value will appear here.
Total interest earned will appear here.
.calculator-wrapper {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, .1);
}
.calculator-form h2, .calculator-result h3 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.calculator-form p {
margin-bottom: 20px;
line-height: 1.6;
color: #555;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.form-group input[type="number"] {
width: calc(100% – 22px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.calculator-form button {
width: 100%;
padding: 12px 15px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.calculator-form button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 30px;
padding: 20px;
background-color: #f9f9f9;
border: 1px solid #eee;
border-radius: 4px;
text-align: center;
}
#totalValue, #totalInterestEarned {
font-size: 1.1em;
color: #28a745;
font-weight: bold;
margin-top: 10px;
}
function calculateCDInterest() {
var initialDeposit = parseFloat(document.getElementById("initialDeposit").value);
var annualInterestRate = parseFloat(document.getElementById("annualInterestRate").value);
var termInMonths = parseInt(document.getElementById("termInMonths").value);
var totalValueElement = document.getElementById("totalValue");
var totalInterestEarnedElement = document.getElementById("totalInterestEarned");
// Clear previous results
totalValueElement.textContent = "";
totalInterestEarnedElement.textContent = "";
// Input validation
if (isNaN(initialDeposit) || initialDeposit <= 0) {
totalValueElement.textContent = "Please enter a valid initial deposit amount.";
totalValueElement.style.color = "red";
return;
}
if (isNaN(annualInterestRate) || annualInterestRate < 0) {
totalValueElement.textContent = "Please enter a valid annual interest rate.";
totalValueElement.style.color = "red";
return;
}
if (isNaN(termInMonths) || termInMonths <= 0) {
totalValueElement.textContent = "Please enter a valid CD term in months.";
totalValueElement.style.color = "red";
return;
}
// Convert annual rate to monthly rate
var monthlyInterestRate = (annualInterestRate / 100) / 12;
// Calculate future value using compound interest formula for each month
var futureValue = initialDeposit;
for (var i = 0; i < termInMonths; i++) {
futureValue *= (1 + monthlyInterestRate);
}
var totalInterestEarned = futureValue – initialDeposit;
// Display results
totalValueElement.textContent = "Estimated Total Value: $" + futureValue.toFixed(2);
totalInterestEarnedElement.textContent = "Estimated Interest Earned: $" + totalInterestEarned.toFixed(2);
totalValueElement.style.color = "#28a745"; // Green color for success
}