Reply
Aaargh, function trouble.
Old 06-30-2007, 08:44 PM Aaargh, function trouble.
Novice Talker

Posts: 12
Location: Somewhere on a Planet.
Trades: 0
I am supposed to be changing the setInterestRate function so that it prompts for the current rate and this rate is then assigned to var interestRate. To confirm this, the function displayInterestRate is called and it writes the value to output window. I will need to perform some math on the the setInterestRate variable. I have highlighted the part I need help with (in red).

Here is the code I've got so far:
var interestRate = 0;
var response;
var amountIn, interest;
function twoDPs(anyNumber)
{
return Math.round (100 * anyNumber) / 100
};

function setInterestRate(interestRate)
{
window.prompt('Enter the interest rate', '') // Insert your code here
};

function displayInterestRate(interestRate)
{
document.write('Current interest rate is ' + interestRate + '%')
};

function calculateInterest(numberOfPounds)
{
// Insert your code here
};


// Insert your code here

// Main program starts here

setInterestRate(interestRate);

displayInterestRate(interestRate);

document.write('<BR><BR><BR><BR>');
// The following code may be changed
response = window.prompt('Do you want to calculate the interest on an amount of money (Y/N)? ','');
while(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)? ','')
}

NinjaKitty is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 07-01-2007, 02:18 AM Re: Aaargh, function trouble.
vangogh's Avatar
Post Impressionist

Posts: 9,845
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
I'm not sure what the problem you're having is, but I do notice that in setInterestRate you ask for the rate, but then you don't do anything with it. I would assume you want

InterestRate = window.prompt('Enter the interest rat', '');

and then return InterestRate before leaving the function.

Your function call might then be

rate = setInterestRate(InterestRate);

so you'd have that value outside the funtion which you can manipulate.

Is that what you're looking for?
__________________
l Search Engine Friendly Web Design | Van SEO Design
l Tips On Marketing, SEO, Design, and Development | TheVanBlog
l Custom WordPress Themes
| Small Business Forum
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 07-01-2007, 10:40 AM Re: Aaargh, function trouble.
Novice Talker

Posts: 12
Location: Somewhere on a Planet.
Trades: 0
I got the prompt part sorted, so it asks for current rate, so I put in the rate, but then when it displays it, it just states that the current rate is 0%. It doesn't display what I entered. Does this make sense?

And yes, I think that is the sort of thing I am after. I have only just learned about functions, so am struggling a bit with this.

Last edited by NinjaKitty; 07-01-2007 at 12:14 PM..
NinjaKitty is offline
Reply With Quote
View Public Profile
 
Old 07-01-2007, 09:44 PM Re: Aaargh, function trouble.
vangogh's Avatar
Post Impressionist

Posts: 9,845
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
That makes sense. I think the issue is that while you're asking the user for input you're not doing anything with that input once you get it. You want to set a variable with the user input.

Also variable you create in a function are only known by that function. That's why you need to return the variable.

I think the code I have in my post above is what you want or something like what you want.
__________________
l Search Engine Friendly Web Design | Van SEO Design
l Tips On Marketing, SEO, Design, and Development | TheVanBlog
l Custom WordPress Themes
| Small Business Forum
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 07-02-2007, 03:25 PM Re: Aaargh, function trouble.
Novice Talker

Posts: 12
Location: Somewhere on a Planet.
Trades: 0
Thank you. Got it all sorted now.
NinjaKitty is offline
Reply With Quote
View Public Profile
 
Old 07-03-2007, 02:57 AM Re: Aaargh, function trouble.
vangogh's Avatar
Post Impressionist

Posts: 9,845
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Cool. Glad to help if I did. And if not them I'm just glad you got it working.
__________________
l Search Engine Friendly Web Design | Van SEO Design
l Tips On Marketing, SEO, Design, and Development | TheVanBlog
l Custom WordPress Themes
| Small Business Forum
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Reply     « Reply to Aaargh, function trouble.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.10131 seconds with 13 queries