Your Estimated CD Earnings
Enter your details above to see your potential earnings.
function calculateCDEarnings() {
var principal = parseFloat(document.getElementById("principalAmount").value);
var apy = parseFloat(document.getElementById("annualPercentageYield").value);
var term = parseFloat(document.getElementById("termInYears").value);
var frequency = parseFloat(document.getElementById("compoundingFrequency").value);
var resultDiv = document.getElementById("result");
if (isNaN(principal) || isNaN(apy) || isNaN(term) || isNaN(frequency) || principal <= 0 || apy < 0 || term <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
var ratePerPeriod = (apy / 100) / frequency;
var numberOfPeriods = term * frequency;
var futureValue = principal * Math.pow((1 + ratePerPeriod), numberOfPeriods);
var totalInterestEarned = futureValue – principal;
resultDiv.innerHTML =
"
Initial Deposit: $" + principal.toFixed(2) + "" +
"
APY: " + apy.toFixed(2) + "%" +
"
Term: " + term + " Year(s)" +
"
Compounding Frequency: " + getFrequencyText(frequency) + "" +
"
Estimated Total Value at Maturity: $" + futureValue.toFixed(2) + "" +
"
Estimated Interest Earned: $" + totalInterestEarned.toFixed(2) + "";
}
function getFrequencyText(frequency) {
switch (frequency) {
case 1: return "Annually";
case 2: return "Semi-Annually";
case 4: return "Quarterly";
case 12: return "Monthly";
case 365: return "Daily";
default: return "Custom";
}
}
.calculator-container {
font-family: 'Arial', sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #e0e0e0;
border-radius: 8px;
background-color: #f9f9f9;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.calculator-header {
text-align: center;
margin-bottom: 25px;
}
.calculator-header h1 {
color: #333;
margin-bottom: 10px;
}
.calculator-header p {
color: #555;
font-size: 1.1em;
}
.calculator-inputs {
display: grid;
grid-template-columns: 1fr;
gap: 15px;
}
.input-group {
display: flex;
flex-direction: column;
align-items: flex-start;
}
.input-group label {
font-weight: bold;
margin-bottom: 5px;
color: #444;
}
.input-group input[type="number"],
.input-group select {
width: calc(100% – 20px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1em;
box-sizing: border-box;
}
.input-group span {
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
font-size: 1em;
color: #555;
pointer-events: none;
}
.input-group {
position: relative; /* Needed for absolute positioning of span */
}
button {
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
font-size: 1.1em;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 10px;
}
button:hover {
background-color: #0056b3;
}
.calculator-results {
margin-top: 30px;
padding: 20px;
border: 1px dashed #007bff;
border-radius: 5px;
background-color: #e7f3ff;
}
.calculator-results h2 {
text-align: center;
color: #007bff;
margin-bottom: 15px;
}
#result p {
margin-bottom: 10px;
color: #333;
font-size: 1.05em;
line-height: 1.5;
}
#result p strong {
color: #007bff;
}
.error {
color: #dc3545 !important;
font-weight: bold;
}