The math doesn't look right to me?
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD><TITLE>Mo8-40am49</TITLE>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<STYLE type=text/CSS>
</STYLE>
<SCRIPT type="text/javascript">
function calc(myform) {
var f=document.forms[0].elements; // identify forms and inputs by their index rather than name or id (personal prefrence)
var interest = f[1].value / 100; // alert(interest)
var total = ((f[0].value - f[2].value) * (1 + f[1].value)); // alert(total)
f[3].value=(total / 60).toFixed(2); // monthly payment
f[4].value=total
}
</SCRIPT>
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY scroll="auto" bgcolor="#FFE4E1">
<h1>Final Exam Car Payment Calculator(CPC)</h1>
<form>
<table border="1" style="text-align:right;border-collapse:collapse">
<tr>
<td>Car Price: <input value="1000" name="price" /></td></tr> <!--default type is text, leave off if text-->
<tr>
<td>Interest rate: <input value="5.5" name="rate" /></td></tr>
<tr>
<td>Number of Years: 5 years (60 months) </td></tr>
<tr>
<td>Down Payment: <input value="90" name="down" /></td></tr>
<tr>
<td>Monthly Payment: <input name="payment" onFocus="this.blur();" /></td></tr><!--Why is this blur? A: this blur becasue you don't get to decide how much to pay per month-->
<tr>
<td>paid after 5 years <input></td></tr>
</table>
<p>
<input type="button" value="Calculate" onClick="calc(this)" /><input type="reset" value="Reset" />
</form>
<hr />
<h3>Question #2</h3>
Write a JavaScript function - calc() with parameter/argument to calculate a car payment:
<ul><li>interest = rate / 100</li>
<li>total = ((price - down) * (1 + interest))</li>
<li>payment = total / 60 </li>
</ul>
</BODY></HTML>
Bookmarks