currency convertor

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jan 2005
Posts: 6
Reputation: mr woo is an unknown quantity at this point 
Solved Threads: 0
mr woo mr woo is offline Offline
Newbie Poster

currency convertor

 
0
  #1
Jan 20th, 2005
Hi there,
I'm a complete novice on javascript and am trying to make a basic currency convertor as part of my college course.
I have the beginning sorted, but am struggling to get the code to output the answer.

Can any kind soul tell me where I'm going wrong?

// Aim; to imput an amount in £'s and output in $'s using an exchange rate of 1.78 //

var amountInPounds, amountInDollars, dollarRate;

document.write('Currency Conversion Application A' + '<BR><BR>');

dollarRate = 1.78;


amountInPounds = window.prompt('PLease enter your sterling amount' ,'');
amountinPounds = parsefloat(amountinPounds);
amountInDollars = amountinPounds * dollarRate;
amountinDollars = parsefloat(amountinDollars);
document.write('total is ' + amountinDollars + '<br>');



Any help gratefully appreciated!

Phil
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 10
Reputation: Javaknight is an unknown quantity at this point 
Solved Threads: 1
Javaknight's Avatar
Javaknight Javaknight is offline Offline
Newbie Poster

Re: currency convertor

 
0
  #2
Jan 21st, 2005
Originally Posted by mr woo
var amountInPounds, amountInDollars, dollarRate;
amountinPounds = parsefloat(amountinPounds);
amountInDollars = amountinPounds * dollarRate;
amountinDollars = parsefloat(amountinDollars);
document.write('total is ' + amountinDollars + '<br>');
Hello Mr. Woo.

I would just like to bring to your attention the suspect lines of code above. (Very simple but effective logic by the way! ) Keep in mind that Javascript is case sensitive so parseFloat() and parsefloat() are two different animals. As is the case with 'amountinPounds' and 'amountInPounds'.

Here is the corrected code back-at-ya:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var amountInPounds, amountInDollars, dollarRate;
  2.  
  3. document.write('Currency Conversion Application A' + '<BR><BR>');
  4.  
  5. dollarRate = 1.78;
  6. amountInPounds = window.prompt('PLease enter your sterling amount' ,'');
  7. amountInPounds = parseFloat(amountInPounds);
  8. amountInDollars = amountInPounds * dollarRate;
  9. amountInDollars = parseFloat(amountInDollars);
  10. document.write('total is ' + amountInDollars + '<br>');
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 6
Reputation: mr woo is an unknown quantity at this point 
Solved Threads: 0
mr woo mr woo is offline Offline
Newbie Poster

Re: currency convertor

 
0
  #3
Jan 21st, 2005
Many thanks for the reply!
With your help I'm getting the hang of it slowly as well as trying to be more precise with the spelling etc

best wishes
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 6
Reputation: mr woo is an unknown quantity at this point 
Solved Threads: 0
mr woo mr woo is offline Offline
Newbie Poster

Re: currency convertor

 
0
  #4
Jan 27th, 2005
Well I'm back again after hitting another stumbling block.
This time I'm trying to input 4 values which the program will display before outputting as a total.

So far I have managed to get it to prompt for & display the values, but instead of giving a total it displays each individual value.

I'm close, but can't see the error.......any idea's ??
...................................................................
<HTML>
<HEAD>
<TITLE>Electric Bills
</TITLE>
<SCRIPT >

/* Program to read in a known number of data items and store them in an array */

var paymentArray = new Array (4);
var total;

document.write('Array program to display a customers four quarterly bills to an Electricity company & show the total due');

total = 0

for (var quarter = 0; quarter < paymentArray.length; quarter = quarter + 1)
{
paymentArray[quarter] = window.prompt('Enter payment value','')

};
document.write('<BR>' + '<BR>');
document.write('Confirmation of amounts payable' + '<BR>' + '<BR>');


for (var quarter = 0; quarter < paymentArray.length; quarter = quarter + 1)
{
document.write(paymentArray[quarter] + '<BR>')

total = total + paymentArray[quarter]
total = parseFloat(total)
}
document.write('total amount paid is ' + total + '<br>')

</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
...............................................................................
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 10
Reputation: Javaknight is an unknown quantity at this point 
Solved Threads: 1
Javaknight's Avatar
Javaknight Javaknight is offline Offline
Newbie Poster

Re: currency convertor

 
0
  #5
Jan 27th, 2005
Originally Posted by mr woo
I'm close, but can't see the error.......any idea's ??
Boy do I know how you feel :!: You were very close! Remember this about Javascript code: the '+' operator acts as both an agent to add numbers and concatenate strings. The latter, concatenation of strings, is what was happening in your code. Notice the two changes that I made to make it work:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. /* Program to read in a known number of data items and store them in an array */
  2.  
  3. var paymentArray = new Array (4);
  4. var total = new Number;
  5.  
  6. document.write('Array program to display a customers four quarterly bills to an Electricity company & show the total due');
  7.  
  8. total = 0
  9.  
  10. for (var quarter = 0; quarter < paymentArray.length; quarter = quarter + 1)
  11. {
  12. paymentArray[quarter] = window.prompt('Enter payment value','')
  13.  
  14. };
  15. document.write('<BR>' + '<BR>');
  16. document.write('Confirmation of amounts payable' + '<BR>' + '<BR>');
  17.  
  18.  
  19. for (var quarter = 0; quarter < paymentArray.length; quarter = quarter + 1)
  20. {
  21. document.write(paymentArray[quarter] + '<BR>')
  22.  
  23. total = total + Number(paymentArray[quarter])
  24. total = parseFloat(total)
  25. }
  26. document.write('total amount paid is ' + total + '<br>')

You are definitely well on your way.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 6
Reputation: mr woo is an unknown quantity at this point 
Solved Threads: 0
mr woo mr woo is offline Offline
Newbie Poster

Re: currency convertor

 
0
  #6
Jan 28th, 2005
Many thanks.
It really is tricky, even when I copied the changes over I wrote 'number' with a small 'n' and it had a wobbly, I wish it wasn't so case sensitive!

I'm working on a Function Library now and some string things so watch this space....something tells me ....... 'I'll be back' :lol:
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 6
Reputation: mr woo is an unknown quantity at this point 
Solved Threads: 0
mr woo mr woo is offline Offline
Newbie Poster

Re: currency convertor

 
0
  #7
Feb 8th, 2005
Well, as expected I'm back...the only surprise is it took me so long!

I'm trying to make a little program which takes a string, doubles any vowels, returning the string with all the vowels doubled in an alert box.
Sadly it has me baffled........

The program is supposed to make use of a function called 'doublevowels' that I made earlier (although I am rather dubious whether that is correct as well!) & imports it from a function library.

So here's where I'm at;

<HTML>
<HEAD>
<TITLE>vowels
</TITLE>
<SCRIPT SRC = "stringLibrary.js"> </SCRIPT>
<SCRIPT >

Function doublevowels(aString)
var answer;

answer = '';

for (var position = 0; position < aString.length; position = position +1)
{
(doublevowels('string goes here'))
}

return answer
window.confirm(+ answer + '<br>')


</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>

Any pointers about what else I need and where will be gratefully appreciated!
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 6
Reputation: mr woo is an unknown quantity at this point 
Solved Threads: 0
mr woo mr woo is offline Offline
Newbie Poster

Re: currency convertor

 
0
  #8
Feb 16th, 2005
All sorted! :cheesy:
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 10
Reputation: Javaknight is an unknown quantity at this point 
Solved Threads: 1
Javaknight's Avatar
Javaknight Javaknight is offline Offline
Newbie Poster

Re: currency convertor

 
0
  #9
Feb 18th, 2005
Originally Posted by mr woo
All sorted! :cheesy:
I'm glad you've done it!! Sorry I didn't have time to assist this time.

However, it seems as though you have graduated!
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 5
Reputation: MrsParadox is an unknown quantity at this point 
Solved Threads: 0
MrsParadox MrsParadox is offline Offline
Newbie Poster

Re: currency convertor

 
0
  #10
Feb 23rd, 2005
Originally Posted by mr woo
All sorted! :cheesy:
perhaps Mr Woo u would be so kind as to share as to how you got it sorted
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC