Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

a. How much must you deposit annually to accumulate this amount

Answered: 1 week ago

Question

10-9 How have social technologies changed e-commerce?

Answered: 1 week ago