Results 1 to 6 of 6

Thread: what am I doing wrong??

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    15

    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

  2. #2
    Addicted Member MrPresident2k's Avatar
    Join Date
    May 2002
    Location
    INDIA
    Posts
    167

    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    15

    Thanx

    thanx for replying Pres
    I'll try that now and get back to you a little later it's much appericated.


    Lisa

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  5. #5
    Addicted Member MrPresident2k's Avatar
    Join Date
    May 2002
    Location
    INDIA
    Posts
    167

    Yes

    Yea,

    We can do that, since we are using parseInt. Thats just for a safety
    ;-)

    Thanks,
    Pres.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width