DCF calculator
document.write(' ');
DCF Calculator
document.write(' ');
script.js:function calculateDCF() {
const cashFlow = parseFloat(document.getElementById('cashFlow').value);
const discountRate = parseFloat(document.getElementById('discountRate').value);
const years = parseFloat(document.getElementById('years').value);
if (isNaN(cashFlow) || isNaN(discountRate) || isNaN(years)) {
alert('Please enter valid numbers');
return;
}
const discountedCashFlow = cashFlow / Math.pow(1 + discountRate / 100, years);
document.getElementById('result').innerHTML = `Discounted Cash Flow: $${discountedCashFlow.toFixed(2)}`;
}style.css:body {
font-family: Arial, sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
}
.calculator {
text-align: center;
}
label {
display: block;
margin-top: 10px;
}
input {
padding: 5px;
margin-bottom: 10px;
}
button {
padding: 8px 16px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}This simple DCF calculator takes inputs for Cash Flow, Discount Rate, and Number of Years, then calculates the Discounted Cash Flow when the user clicks the "Calculate DCF" button. The result is displayed below the button.
Comments