rendered paste body<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><title>Payment Comparison</title><script language=javascript><!--Start Hide//**********************************************start Decimal Placesfunction DecimalPlaces(n,p){ //var currentrate = 0; var factor = 1; var ans = 0; var j = 0; var k=0; var look=false; var ansLength=new String(); for (j = 1; j <= p; j++) { factor = factor * 10.0; } ans = (Math.round((n + 0.05 / (factor) ) * factor)) / factor; ansLength=ans + ""; for (x=0; x<ansLength.length; x++) { //check each character in the string against the acceptable characters var theChar=ansLength.charAt(x); if (theChar==".") { k=x; break; } } if (k==0) { ans1=ans+".00"; look=true; } ansSub=ansLength.substring(k); if(n > 1) { if(!look) { if (ansSub.length==2) { ans1=ans + "0"; } else if (ansSub.length==3) { ans1=ans; } } } else { ans1=ans; } return ans1;}//end of decimal places//*******************************************end of decimalplaces**********************************var interestrate=0;var payyears=0;var stepvalue=1;var loanamount=0;var term=1;var payment=0;var lowinterestrate=0;var highinterestrate=0;var currentrate=0;function validate(){ interestrate=parseFloat(document.comparison.interestRate.value); payyears=parseFloat(document.comparison.payYears.value); loanamount=parseFloat(document.comparison.loanAmount.value); if(isNaN(interestrate) || interestrate <=0) { alert("Please enter a value larger than 0 for the interestrate"); }//end of interstrate else { if(isNaN(loanamount) || loanamount <=100) { alert("Please enter a number equal to or larger than 100 for the loan amount"); }//end of loanamount if else { if(isNaN(payyears) || payyears <1) { alert("Please enter a value of 1 or greater for the number of years"); }//end of payyears if else { createComparison(); //alert("The form is valid"); }//end of payyears }//end of else loan amount }//end of else interestrate}//end of validatefunction createComparison(){ if(interestrate>1) { interestrate/=100; }//end of if interestrate >1 lowinterestrate=interestrate - .03; highinterestrate=interestrate + .03; for(count=0;count<document.comparison.stepValue.length;count++) { if(document.comparison.stepValue[count].checked==true) { stepvalue=parseFloat(document.comparison.stepValue[count].value); }//end of checked }//end of for count loop document.write("<table>"); document.write("<tr>"); document.write("<th>Interest Rate</th>"); document.write("<th> </th>"); document.write("<th>Amount Borrowed</th>"); document.write("<th> </th>"); document.write("<th>Total of Payments</th>"); document.write("</tr>"); for (lowValue=lowinterestrate; lowValue<=highinterestrate; lowValue += stepvalue) { term=Math.pow((1+ (lowValue/12)),(12 * payyears)); payment=(loanamount * (lowValue/12) * term)/(term-1); displayOutput(); }//end of for loop //alert("the step value is: " + stepvalue); }//end of createComparisonfunction displayOutput(){ var totalofpayments=parseFloat(payment) * (payyears * 12); document.write("<table>"); document.write("<tr>"); document.write("<td style='text-align:right;'>" + currentrate + "</td>"); document.write("<td> </td>"); document.write("<td style='text-align:right;'>" + payment + "</td>"); document.write("<td> </td>"); document.write("<td style='text-align:right;'>" + loanamount + "</td>"); document.write("<td> </td>"); document.write("<td style='text-align:right;'>" + totalofpayments + "</td>"); document.write("</table>");// alert(payment);}//end of displayOutput// end of hide --></script></head><body><h1 style="text-align:center;">Aiken Tech Evening Javascript Class<br>Payment Comparison</h1><table style="text-align:center; width:700px;"> <tr> <th colspan="3">Enter the information below and I will give you<br>a comparison of payments for the amount you would like to borrow.</th> </tr><form name="comparison" id="comparison"> <tr> <td colspan="3" style="text-align:center;"> </td> </tr> <tr> <th>Starting Interest Rate</th> <th>Amount of Loan</th> <th>Number of Years of Loan</th> </tr> <tr> <td style="text-align:center;"> <input type="text" name="interestRate" id="interestRate" size="4" maxlength="4" /> <p>Step Increase</p> <div style="width:50px;"> <p style="text-align:left"> <input type="radio" name="stepValue" id="stepValue1" value=".0025" checked />1/4%<br /> <input type="radio" name="stepValue" id="stepValue2" value=".005" />1/2%<br /> <input type="radio" name="stepValue" id="stepValue3" value=".0075" />3/4%<br /> <input type="radio" name="stepValue" id="stepValue4" value=".01" />1% </p> </div> </td> <td style="text-align:center; vertical-align:top;"> <input type="text" name="loanAmount" id"loanAmount" size="6" maxlength="6" /> </td> <td style="text-align:center; vertical-align:top;"> <input type="text" name="payYears" id="payYears" size="2" maxlength="2" /> </td> </tr> <tr> <td colspan="3" style="text-align:center;"> </td> </tr> <tr> <td colspan="3" style="text-align:center;"> <input type="button" name="calculate" id="calculate" value="Compare" onClick="validate();" /> <input type="reset" name="btnreset" id="btnreset" value="Reset" /> </td> </tr></form></table></body></html>