Complete Code of Discounted Cash Flow Calculator

 Here is the Complete code of Discounted Cash Flow Calculator Tool for free, you just need to copy and paste the code and run it. 


<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Discounted Cash Flow Calculator</title>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">

    <style>

        body {

            font-family: Arial, sans-serif;

            background: linear-gradient(to right, #f7b42c, #fc575e);

            color: #333;

            margin: 0;

            padding: 0;

            display: flex;

            justify-content: center;

            align-items: center;

            height: 100vh;

        }


        .container {

            background-color: #fff;

            border-radius: 10px;

            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);

            width: 100%;

            max-width: 600px;

            padding: 20px;

        }


        .container h1 {

            text-align: center;

            margin-bottom: 20px;

            color: #fc575e;

        }


        .form-group {

            margin-bottom: 15px;

        }


        .form-group label {

            display: block;

            font-weight: bold;

            margin-bottom: 5px;

        }


        .form-group input {

            width: 100%;

            padding: 10px;

            border: 1px solid #ccc;

            border-radius: 5px;

            font-size: 1rem;

        }


        .btn {

            background: #fc575e;

            color: #fff;

            padding: 10px 20px;

            border: none;

            border-radius: 5px;

            font-size: 1rem;

            cursor: pointer;

            display: block;

            width: 100%;

            margin-top: 20px;

            text-align: center;

        }


        .btn:hover {

            background: #f7b42c;

        }


        .results {

            margin-top: 20px;

            background: #f9f9f9;

            padding: 15px;

            border-radius: 5px;

            border: 1px solid #ddd;

        }


        .results p {

            font-size: 1rem;

            margin: 5px 0;

        }

    </style>

</head>

<body>

    <div class="container">

        <h1>Discounted Cash Flow Calculator</h1>

        <div class="form-group">

            <label for="cashFlow">Annual Cash Flow ($):</label>

            <input type="number" id="cashFlow" placeholder="Enter annual cash flow">

        </div>

        <div class="form-group">

            <label for="discountRate">Discount Rate (%):</label>

            <input type="number" id="discountRate" placeholder="Enter discount rate">

        </div>

        <div class="form-group">

            <label for="years">Number of Years:</label>

            <input type="number" id="years" placeholder="Enter number of years">

        </div>

        <button class="btn" onclick="calculateDCF()">Calculate</button>

        <div class="results" id="results" style="display: none;">

            <h3>Results:</h3>

            <p id="dcfValue"></p>

        </div>

    </div>


    <script>

        function calculateDCF() {

            const cashFlow = parseFloat(document.getElementById('cashFlow').value);

            const discountRate = parseFloat(document.getElementById('discountRate').value) / 100;

            const years = parseInt(document.getElementById('years').value);


            if (isNaN(cashFlow) || isNaN(discountRate) || isNaN(years) || cashFlow <= 0 || discountRate <= 0 || years <= 0) {

                alert('Please enter valid positive numbers for all fields.');

                return;

            }


            let dcf = 0;

            for (let i = 1; i <= years; i++) {

                dcf += cashFlow / Math.pow(1 + discountRate, i);

            }


            document.getElementById('dcfValue').innerText = `The Discounted Cash Flow (DCF) is: $${dcf.toFixed(2)}`;

            document.getElementById('results').style.display = 'block';

        }

    </script>

</body>

</html>


Admin

A Software Engineer, Social Media Marketing Expert, writer,

Post a Comment

Previous Post Next Post