-
what am I doing wrong??
PLEASE HELP ME!!! otherwise I will have a nervous breakdown, I'm learning javasript(very new to this)and have been ask to write a code to work out simple interest rate. here is my feeble attempt at it;<html>
<head>
<title> Headwreaker</title>
<script type = "text/javascript">
<!--
var Name, // first string entered by user
Address, // second string entered by user
DOB, // Date of Birth
Occupation, // job
p, //Amount entered by user
n, //How long the loan is for in years
i, // interest
fixedInterest,
amount,
years,
firstno,
secno,
// read in name from user as a string
Name =
window.prompt( "Enter name", "" );
// read in address from user as a string
Address =
window.prompt( "Enter address", "" );
// read in DOB from user as a string
DOB =
window.prompt( "Enter DOB", "" );
// read in Occupation from user as a string
Occupation =
window.prompt( "Enter Occupation", "" );
// read in Amount from user as a string
p=
window.prompt( "Enter the amount of loan ", "0" );
// read in Period from user as a string
n=
window.prompt( "Enter the loan in years", "0" );
// convert numbers from strings to integers
p = parseFloat(firstno);
n = parseFloat(secno);
// Simple intrest
// Formula i = interest P amount n No of years
// A = amount after No of years
sum = Math.(p*(1+n*i));
//function to calculate Fixed interest
//function Interest()
//var i=0.088;
//var fixedInterest=P*(1)+(n);
document.write("sum",+ sum);
</script>
</head>
<body>
<p>Click Refresh (or Reload) to run the script again</p>
</body>
</html>
It would be much appericated otherwise I'll have to phone the samatrians!!!
Thanx Lisa
:confused:
-
Try with this
Hi,
Try with this.
Code:
<html>
<head>
<title>
Headwreaker
</title>
<head>
<body>
<script Language = "javascript">
var Name, // first string entered by user
Address, // second string entered by user
DOB, // Date of Birth
Occupation, // job
p, //Amount entered by user
n, //How long the loan is for in years
i, // interest
fixedInterest,
amount,
years,
firstno,
secno;
// read in name from user as a string
Name = window.prompt( "Enter name", "" );
// read in address from user as a string
Address = window.prompt( "Enter address", "" );
// read in DOB from user as a string
DOB = window.prompt( "Enter DOB", "" );
// read in Occupation from user as a string
Occupation = window.prompt( "Enter Occupation", "" );
// read in Amount from user as a string
p= window.prompt( "Enter the amount of loan ", "0" );
// read in Period from user as a string
n= window.prompt( "Enter the loan in years", "0" );
// convert numbers from strings to integers
p = parseFloat(p);
n = parseFloat(n);
var i=0.088;
// Simple intrest
// Formula i = interest P amount n No of years
// A = amount after No of years
sum = eval(p*(1+n*i));
//function to calculate Fixed interest
//function Interest()
//var i=0.088;
//var fixedInterest=P*(1)+(n);
document.write("sum = " + sum);
</script>
<br><br>
<p>
Click Refresh (or Reload) to run the script again</p>
</body>
</html>
Good Luck,
Pres.
-
Thanx
thanx for replying Pres
I'll try that now and get back to you a little later it's much appericated.
Lisa
-
Why do you use eval?
sum = p*(1+n*i);
Assuming the formula is correct, this would work too.
-
Yes
Yea,
We can do that, since we are using parseInt. Thats just for a safety
;-)
Thanks,
Pres.
-
That's the thing I hate most about JavaScript. Using + for both concatenation and addition in a non-typed language is madness!