Assignment J Credit Card Payoff Calculator Key prugramming concepts: toriables,
ID: 3877399 • Letter: A
Question
Explanation / Answer
Answer)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<script>
function getAdjustedRate(rate){//returns adjustedRate
var days=365;
var power=30.4167;
return (Math.pow(1+rate/(100*days),power)-1);
}
function getMonths(adjustedRate,bal,monthlyInstallment){//returns number of months to pay for fixed monthly installement
return Math.ceil(-Math.log(1-(adjustedRate*bal)/monthlyInstallment)/Math.log(1+adjustedRate));
}
function getPayment(adjustedRate,bal,month){//returns payment for given months adjustedRate and months
return ((adjustedRate*bal)/(1-Math.pow(1+adjustedRate,-month)));
}
function func(){//called on invoking submit button
var bal=document.getElementById("bal").value;//get balance from html
var rate=document.getElementById("rate").value;//get rate from html
var monthlyInstallment=document.getElementById("mi").value;//get monthly installment from html
var adjustedRate=getAdjustedRate(rate);
var months=getMonths(adjustedRate,bal,monthlyInstallment);
var payoff=monthlyInstallment*months;//calculate payoff
document.getElementById("p1").innerHTML=monthlyInstallment;//display monthly installment for option 1)
document.getElementById("m1").innerHTML=months;//display months for option 1)
document.getElementById("pay1").innerHTML=(payoff.toFixed(2));//display payoff for option 1)
monthlyInstallment*=2;
document.getElementById("p2").innerHTML=monthlyInstallment;//display monthly installment for option 2)
months=getMonths(adjustedRate,bal,monthlyInstallment);
document.getElementById("m2").innerHTML=months;//display months for option 2)
document.getElementById("pay2").innerHTML=((monthlyInstallment*months).toFixed(2));
//display payoff for option 2)
months=3;
var monthlyInstallment=getPayment(adjustedRate,bal,months);
document.getElementById("p3").innerHTML=monthlyInstallment;//display monthly installment for option 3)
document.getElementById("m3").innerHTML=months;//display months for option 3)
document.getElementById("pay3").innerHTML=((monthlyInstallment*months).toFixed(2));
//display payoff for option 3)
document.getElementById("result").style.display='block';//show result table
document.getElementById("input").style.display='none';//hide input table
}
</script>
</head>
<body>
<table cellpadding="4" id="input"><!-- table to get input-->
<tr><td>
Balanced Owed:</td>
<td><input type="number" id="bal"></input></td>
</tr>
<tr>
<td>Interest Rate:</td>
<td><input type="number" id="rate"></input></td>
</tr>
<tr>
<td>Monthly Installment:</td>
<td><input type="number" id="mi"></input></td>
<tr>
<td colspan="2"><input type="button" value="submit"></td>
</table>
<table id="result" cellpadding="4"><!-- table to show ouput-->
<thead>
<th>Otption</th>
<th>Payment</th>
<th>Months</th>
<th>Payoffs</th>
</thead>
<tbody>
<tr>
<td>1)</td>
<td id="p1"></td>
<td id="m1"></td>
<td id="pay1"></td>
</tr>
<tr>
<td>2)</td>
<td id="p2"></td>
<td id="m2"></td>
<td id="pay2"></td>
</tr>
<tr>
<td>3)</td>
<td id="p3"></td>
<td id="m3"></td>
<td id="pay3"></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.