PDA

View Full Version : javascript using if else in the main part of the programme needs help



java dummie
Jun 25th, 2007, 08:05 PM
I have been writing a program to store the interest rates for different institutions for current accounts, savings accounts and
e-savings accounts. These interest rates should be printed out
on request.my question is to Write the main part of the program in which a user is repeatedly
asked whether they want to add a new institution (A or a),
print out the rates (P or p) or quit (Q or q) and which calls
the appropriate function. Note that the program should accept
the input in upper or lower case. If the user inputs an
unrecognised input then the program should just continue to
prompt for the next action. so far i have got this but really stuck on what to do next. please help me, i am not looking for the full answer just some hints and tips will do.
Thanks
<HTML>
<HEAD> bank rates
<TITLE>Enter a number </TITLE>
<SCRIPT language="JavaScript" >

var institutionArray = ['Pennygo Bank','Cardew Bank','Summer Bank','','','','','','',''];

var currentArray = ['2.0','1.5','1.8','0','0','0','0','0','0','0'];

var savingsArray = ['4.0','3.75','4.2','0','0','0','0','0','0','0'];

var esavingsArray = ['4.5','4.75','4.2','0','0','0','0','0','0','0'];

var userNumber;

function addInstitution ()
{
bankNames = window.prompt('Please enter the name of your bank ', 'bankNamesArray');
current = parseFloat(window.prompt('Please enter your Current account rate ', ""));
savings = parseFloat(window.prompt('Please enter your Savings account rate ', ""));
eSavings = parseFloat(window.prompt('Please enter your eSavings account rate ', ""));
};

function displayRates()
{
for (var bank = 0; bank < bankNamesArray.length; bank++)
document.write(bankNamesArray[bank] + ' : ' + currentArray[bank] + '<BR>' + savingsArray[bank] + '<BR>' +eSavingsArray[bank] + '<BR>');
};

// Main program starts here

addInstitution();

displayRates();

document.write('<BR><BR><BR><BR>');

response = window.prompt('Do you want to calculate the interest on an amount of money (Y/N)? ','');
{
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)? ','')
document.write(' '+ amountInPounds + ' attracts ' + interest + ' interest');
</script>
</head>
<body>
</body>
</html>

java dummie
Jun 25th, 2007, 08:12 PM
i am supposed to be using the IF ELSE structure for the main part of the programme.