SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calculating Interest - A program

    Hello All! I've just started with java a couple of months ago, and was wondering if anyone could tell me what's wrong here. I've written the code spot on according to instructions except I can't get the amount of interest to get calculated and displayed

    Code:
    <HTML>
    
    <HEAD>
    
    <TITLE>Interest Rate</TITLE>
    
    <SCRIPT>
    
    var interestRate = 0;
    
    var response;
    
    var amountInPounds;
    
    var interest;
    
    function twoDPs(anyNumber)
    
    {
    
        return Math.round (100 * anyNumber) / 100
    
    }; 
    
    
    
    function setInterestRate()
    
    {
    
    	InterestRate = parseInt(window.prompt('Please enter the rate of Interest Rate of your choosing' + ''), 10)
    
    };
    
    
    
    function displayInterestRate()
    
    {
    
    	document.write('<BR>' + 'Current interest rate is ' + interestRate + '%')	
    
    };
    
    
    
    function calculateInterest(numberOfPounds) 
    
    {
    interest = numberOfPounds * interestRate / 100;
    interest = twoDPs(interest); // or interest = interest.toFixed(2);
    }; 
    
    
    setInterestRate();
    
    displayInterestRate();
    
    document.write('<BR><BR><BR><BR>'); 
    
    
    response = window.prompt('Do you want to calculate the interest on an amount of money (Y/N)? ','');
    
    while(response == 'Y' || response == 'y')
    
    {
    
    	amountInPounds = window.prompt('Enter amount in Pounds ','');
    
    	interest = calculateInterest(amountInPounds);
    
    	document.write(' '+ amountInPounds + ' attracts ' + interest + ' interest');
    
    	document.write('<BR><BR><BR>');  
    
    	response = window.prompt('Do you want to calculate the interest for another amount (Y/N)? ','')	
    
    }
    
    
    
    </SCRIPT>
    
    </HEAD>
    
    
    
    <BODY>
    
    </BODY>
    
    </HTML>

  2. #2
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,108
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    Spelling mistake on InterestRate.

    How are you learning javascript - because the methods you are using in this script are pretty bad ones..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •