diff --git a/Calculators/NPV-Calculator/README.md b/Calculators/NPV-Calculator/README.md new file mode 100644 index 000000000..6caeeeff1 --- /dev/null +++ b/Calculators/NPV-Calculator/README.md @@ -0,0 +1,27 @@ +#

NPV Calculator

+ +## Description :- + +Given an initial investment, the discount rate (per year), and the yearly cash flows, this calculator calculates the NPV (Net Present Value) of the investment. NPV is a financial metric used to evaluate the profitability of an investment or project. + +## Tech Stacks :- + +- HTML +- CSS +- JavaScript + +## Formula Used :- + +The formula for calculating NPV is: + +\[ NPV = \sum \left( \frac{CF_t}{(1 + r)^t} \right) - C_0 \] + +Where: +- \( CF_t \) is the cash flow at time \( t \) +- \( r \) is the discount rate +- \( C_0 \) is the initial investment +- \( t \) is the time period (year) + +## Screenshots :- + +![image](https://github.com/Manav173/CalcDiverse/assets/73993775/640d6aa4-b68b-4057-865c-bee17e8c7e1b) diff --git a/Calculators/NPV-Calculator/index.html b/Calculators/NPV-Calculator/index.html new file mode 100644 index 000000000..61bb80cb3 --- /dev/null +++ b/Calculators/NPV-Calculator/index.html @@ -0,0 +1,36 @@ + + + + + + + + NPV Calculator + + + +
+

Net Present Value (NPV) Calculator

+
+ + +
+
+ + +
+
+ +
+ +
+ +
+
NPV: Rs. 0.00
+
+
+ + + + + diff --git a/Calculators/NPV-Calculator/script.js b/Calculators/NPV-Calculator/script.js new file mode 100644 index 000000000..e096a707f --- /dev/null +++ b/Calculators/NPV-Calculator/script.js @@ -0,0 +1,42 @@ +let cashFlowCount = 0; + +function addCashFlow() { + cashFlowCount++; + const cashFlowsDiv = document.getElementById('cashFlows'); + const newCashFlow = document.createElement('div'); + newCashFlow.className = 'cash-flow-item'; + newCashFlow.innerHTML = ` + + + + `; + cashFlowsDiv.appendChild(newCashFlow); +} + +function removeCashFlow(button) { + const cashFlowItem = button.parentElement; + cashFlowItem.remove(); +} + +function calculateNPV() { + const initialInvestment = parseFloat(document.getElementById('initialInvestment').value); + const discountRate = parseFloat(document.getElementById('discountRate').value) / 100; + const cashFlowItems = document.querySelectorAll('.cash-flow-item input'); + + if (isNaN(initialInvestment) || isNaN(discountRate)) { + alert('Please enter valid inputs.'); + return; + } + + let npv = -initialInvestment; + cashFlowItems.forEach((input, index) => { + const cashFlow = parseFloat(input.value); + if (isNaN(cashFlow)) { + alert('Please enter valid cash flow values.'); + return; + } + npv += cashFlow / Math.pow(1 + discountRate, index + 1); + }); + + document.getElementById('npvResult').textContent = npv.toFixed(2); +} diff --git a/Calculators/NPV-Calculator/style.css b/Calculators/NPV-Calculator/style.css new file mode 100644 index 000000000..67c84cb08 --- /dev/null +++ b/Calculators/NPV-Calculator/style.css @@ -0,0 +1,71 @@ +body { + font-family: 'Arial', sans-serif; + background: linear-gradient(to right, #f48a8a, #a3dbf5); + margin: 0; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; +} + +.calculator-container { + background-color: #fff; + border-radius: 10px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + padding: 20px; + width: 500px; + text-align: center; +} + +h1 { + color: #333; +} + +.input-container { + margin-bottom: 15px; +} + +label { + display: block; + margin-bottom: 5px; + color: #555; +} + +input { + width: 100%; + padding: 8px; + border: 1px solid #ddd; + border-radius: 5px; + box-sizing: border-box; +} + +button { + background-color: #4caf50; + color: #fff; + padding: 10px 20px; + border: none; + border-radius: 5px; + cursor: pointer; + font-size: 16px; +} + +button:hover { + background-color: #45a049; + transform: scale(1.05); + transition: 0.2s ease-in-out; +} + +.result-container { + margin-top: 20px; +} + +#result { + font-size: 18px; + font-family: 'Courier New', Courier, monospace; + font-weight: bold; + color: #333; +} + +.red { + color: #f44336; +} \ No newline at end of file diff --git a/index.html b/index.html index b555f8e1c..bb4ce1309 100644 --- a/index.html +++ b/index.html @@ -1252,6 +1252,20 @@

Calculates the multiplication table of any number.

+
+
+

NPV Calculator

+

Calculates the Net Present Value based on initial investment, the discount rate, and the yearly cash flows.

+ +
+

Neon Number Calculator