|
-
Oct 28th, 2002, 05:15 PM
#1
Thread Starter
New Member
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
-
Oct 29th, 2002, 01:58 AM
#2
Addicted Member
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.
-
Oct 29th, 2002, 04:32 AM
#3
Thread Starter
New Member
Thanx
thanx for replying Pres
I'll try that now and get back to you a little later it's much appericated.
Lisa
-
Oct 29th, 2002, 03:49 PM
#4
Why do you use eval?
sum = p*(1+n*i);
Assuming the formula is correct, this would work too.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 29th, 2002, 11:24 PM
#5
Addicted Member
Yes
Yea,
We can do that, since we are using parseInt. Thats just for a safety
;-)
Thanks,
Pres.
-
Oct 30th, 2002, 10:47 AM
#6
That's the thing I hate most about JavaScript. Using + for both concatenation and addition in a non-typed language is madness!
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|