PDA

View Full Version : help



vbean
03-26-2009, 04:41 PM
im a beginner. i have this program but the answer says "undefined" what's wrong?


<HTML>
<HEAD>
<TITLE> BAD CREDIT </TITLE>
<SCRIPT type="text/javascript">
function monthlyRate () {
var price =
parseFloat(document.getElementById("price").value);
var interest =
parseFloat(document.getElementById("interest").value);
var pay=
parseFloat(document.getElementById("pay").value);
if (isNaN(price) || isNaN(interest) || isNaN(pay)) {
return;
}


price.toFixed(2)
var interest = "+ interest +" ;
var monthrate = interest / 100 ;
monthrate = monthrate + 1 ;
monthrate = ((Math.pow(1 + interest , 1/12)) - 1);

var monthly = monthrate;
var bill = "+ price +" ;
var month = 0;
var pay = "+ pay +" ;


while ( bill >= pay ) {
bill = price - pay ;
bill = bill * (1 + monthly);
price = bill ;

}
if ( bill < pay ) {
var totalamount = pay * month + bill ;

}

document.getElementById("amount").value = totalamount;


}


</SCRIPT>
</HEAD>
<BODY>
Enter the purchase price for the item you are interested in buying: <input onchange=monthlyRate() size=13 type=text id=price /><br/>
Enter the annual interest rate on your credit card: <input onchange=monthlyRate() size=13 type=text id=interest /><br/>
Enter the amount of money you plan to pay towards you credit card balance each month: <input onchange=monthlyRate() size=13 type=text id=pay /><br/>
The amount you actually spent is: <input size=5 type=text id=amount /><br/>

codeexploiter
03-27-2009, 04:26 AM
Some variables that you've used in computation seems to be of String type and that creates the issues.