1let cashFlowCount = 0; 2 3function addCashFlow() { 4 cashFlowCount++; 5 const cashFlowsDiv = document.getElementById('cashFlows'); 6 const newCashFlow = document.createElement('div'); 7 newCashFlow.className = 'cash-flow-item'; 8 newCashFlow.innerHTML = ` 9 <label for="cashFlow${cashFlowCount}">Year ${cashFlowCount} : <br> â¹</label> 10 <input class="form-control" id="cashFlow${cashFlowCount}" type="number"/> 11 <button type="button" onclick="removeCashFlow(this); cashFlowCount--;">x</button> 12 `; 13 cashFlowsDiv.appendChild(newCashFlow); 14} 15 16function removeCashFlow(button) { 17 const cashFlowItem = button.parentElement; 18 cashFlowItem.remove(); 19} 20 21function calculateNPV() { 22 const initialInvestment = parseFloat(document.getElementById('initialInvestment').value); 23 const discountRate = parseFloat(document.getElementById('discountRate').value) / 100; 24 const cashFlowItems = document.querySelectorAll('.cash-flow-item input'); 25 26 if (isNaN(initialInvestment) || isNaN(discountRate)) { 27 alert('Please enter valid inputs.'); 28 return; 29 } 30 31 let npv = -initialInvestment; 32 cashFlowItems.forEach((input, index) => { 33 const cashFlow = parseFloat(input.value); 34 if (isNaN(cashFlow)) { 35 alert('Please enter valid cash flow values.'); 36 return; 37 } 38 npv += cashFlow / Math.pow(1 + discountRate, index + 1); 39 }); 40 41 document.getElementById('npvResult').textContent = npv.toFixed(2); 42}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.