Question: debug fv.js for TWO errors????? use strict; var $ = function (id) { return document.getElementById(id); } var calculateFV = function(investment, rate, years) { var futureValue

debug fv.js for TWO errors?????

"use strict"; var $ = function (id) { return document.getElementById(id); } var calculateFV = function(investment, rate, years) { var futureValue = investment; for (var i = 1; i <= years; i++ ) { futureValue += futureValue * rate / 100; } futureValue = futureValue.toFixed(2); return futureValue; } var processEntries = function() { var investment = $("investment"); var rate = $("annual_rate"); var years = $("years"); var ok = true; if (investment.value == "") { investment.nextElementSibling.firstChild.nodeValue = "Principal Investment is required."; ok = false; } else if (isNaN(parseFloat(investment.value))) { investment.nextElementSibling.firstChild.nodeValue = "Must be numeric."; ok = false; } else if (investment.value<1 || investment.value>100000) { investment.nextElementSibling.firstChild.nodeValue = "Must be 1..100000."; ok = false; } else { investment.nextElementSibling.firstChild.nodeValue = ""; } if (rate.value == "") { rate.nextElementSibling.firstChild.nodeValue = "Rate is required."; ok = false; } else if (isNaN(parseFloat(rate.value))) { rate.nextElementSibling.firstChild.nodeValue = "Must be numeric."; ok = false; } else if (rate.value<1 || rate.value>15) { rate.nextElementSibling.firstChild.nodeValue = "Must be 1..15."; ok = false; } else { rate.nextElementSibling.firstChild.nodeValue = ""; } if (years.value == "") { years.nextElementSibling.firstChild.nodeValue = "Years is required."; ok = false; } else if (isNaN(parseInt(years.value))) { years.nextElementSibling.firstChild.nodeValue = "Must be integer."; ok = false; } else if (years.value<1 || years.value>50) { years.nextElementSibling.firstChild.nodeValue = "Must be 1..50."; ok = false; } else { years.nextElementSibling.firstChild.nodeValue = ""; } if (ok) { $("future_value").value = calculateFV(parseFloat(investment), parseFloat(rate), parseInt(years)); } else { $("future_value").value = ""; } }

window.onload = function () { $("calculate").onclick = processentries; $("investment").focus(); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!