SitePoint Sponsor

# Thread: Calculating Interest - A program

1. ## 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. Spelling mistake on InterestRate.

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

#### Posting Permissions

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