Link to home
Start Free TrialLog in
Avatar of sqlagent007
sqlagent007Flag for United States of America

asked on

(500 easy points) how to write a Jscript calculator

I would like to create a calculator in VBScript or JScript that wll take 3 inputs from text boxes and generate output.

input:
Loan Amount <some figure>
Intrest rate <7% or something>
Years <like a 15 year loan or something>

Output:
Number of payments
Monthly Payment
ASKER CERTIFIED SOLUTION
Avatar of rnby
rnby

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rnby
rnby

@AnnieMod
I do understand that that shouln't be allowed.
But how do I know that it's an Homework question?

RNBY
I will try to give attention to that.
I just didn't know,
(And even couldn't remember reading it in the rules)
But we learn from mistakes.
I looked at his other questions but didn't see any of them deleted.
Maybe you should give a good look to his other questions.
Or even ask him himself where this is for.

RNBY
ok, iI fully understand it,
thanks for pointing it out to me.
I will be more carefull the next time.

RNBY
Avatar of sqlagent007

ASKER

Okay, I am sorry to have created this confusion. I am posting the original code just so there are no discrepancies. I am trying to learn web development, and we have a curriculum through our corporate training program. So I guess this would be academic tutoring, but the corporate training program is not accredited by any means.

Again I am not a high school student posting homework, but my HTML is at the level of a 6th grader.

Sorry for the confusion.

#####
/*************************************************************************\
boolean isExpiryDate([int year, int month])
return true if the date is a valid expiry date,
else return false.
\*************************************************************************/
function isExpiryDate() {
var argv = isExpiryDate.arguments;
var argc = isExpiryDate.arguments.length;

year = argc > 0 ? argv[0] : this.year;
month = argc > 1 ? argv[1] : this.month;

if (!isNum(year+""))
return false;
if (!isNum(month+""))
return false;
today = new Date();
expiry = new Date(year, month);
if (today.getTime() > expiry.getTime())
return false;
else
return true;
}

<!-- BEGINNING OF CODE FOR MORTGAGE CALCULATOR -->
<form
action="POST" name="myform">
<table border="1"
bgcolor="#63639C">
<tr>
<td align="center" colspan="2">
<script language="JavaScript">
<!-- function Morgcal()
{ form = document.myform
LoanAmount= form.LoanAmount.value DownPayment= "0" AnnualInterestRate = form.InterestRate.value/100 Years= form.NumberOfYears.value MonthRate=AnnualInterestRate/12 NumPayments=Years*12 Prin=LoanAmount-DownPayment MonthPayment=Math.floor((Prin*MonthRate)/(1-Math.pow((1+MonthRate),(-1*NumPayments)))*100)/100 form.NumberOfPayments.value=NumPayments form.MonthlyPayment.value=MonthPayment
} // --></script> <font color="#FFFFFF" size="2"
face="arial narrow">
<b>Repayment Mortgage Calculator</b>
<br> Enter Your Details &amp; Click the Calculate Button</font></td>
</tr>
<tr>

<td><table border="0" cellpadding="2">
<tr>
<td align="right"><font color="#FFFFFF"
size="2" face="arial narrow">Loan Amount $
</font></td>
<td>
<font color="black" size="2" face="arial narrow">
<input type="text" size="10" name="LoanAmount"
value="80000" onblur="Morgcal()" onchange="Morgcal()"><br>
</font></td>
</tr> <tr>
<td align="right"><font
color="#FFFFFF" size="2" face="arial narrow">
Annual Interest Rate
</font></td>
<td><font color="#FFFFFF"
size="2" face="arial narrow">
<input type="text"
size="3" name="InterestRate" value="6.0" onblur="Morgcal()"
onchange="Morgcal()"> %
<br> </font></td> </tr>
<tr> <td align="right">
<font color="#FFFFFF"
size="2" face="arial narrow">Term of Loan
</font></td>
<td><font color="#FFFFFF" size="2" face="arial
narrow"><input type="text" size="3" name="NumberOfYears"
value="20" onblur="Morgcal()" onchange="Morgcal()">
Years<br> </font></td> <td><font color="#FFFFFF"
size="2" face="arial narrow"><input type="button"

name="morgcal" value="Calculate" language="JavaScript"

onclick = "Morgcal()" </font></td> </tr> <tr>
<td colspan="3"><font color="#FFFFFF"></font></td>
</tr> </table> </td> </tr> <tr> <td><table
border="0" cellpadding="2"> <tr> <td align="right"><font
color="#FFFFFF" size="2" face="arial narrow">
Number of Payments </font></td> <td><font color="#FFFFFF"
size="2" face="arial narrow"><input type="text"
size="7" name="NumberOfPayments"><br> </font></td>
</tr> <tr> <td align="right"><font color="#FFFFFF"
size="2" face="arial narrow">Monthly Payment $ </font></td>
<td><font color="#FFFFFF" size="2" face="arial
narrow"><input type="text" size="7" name="MonthlyPayment"><br>
</font></td> </tr> <tr> <td align="center"
colspan="2">&nbsp;</td> </tr> </table> </td>
</tr> </table>

</form>

</HEAD>
Thanks for informing us on that.
Sorry for any wrong accusations.
Good luck with your training program
RNBY