| | |
currency convertor
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2005
Posts: 6
Reputation:
Solved Threads: 0
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
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
•
•
•
•
Originally Posted by mr woo
var amountInPounds, amountInDollars, dollarRate;
amountinPounds = parsefloat(amountinPounds);
amountInDollars = amountinPounds * dollarRate;
amountinDollars = parsefloat(amountinDollars);
document.write('total is ' + amountinDollars + '<br>');
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)
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>');
•
•
Join Date: Jan 2005
Posts: 6
Reputation:
Solved Threads: 0
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>
...............................................................................
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>
...............................................................................
•
•
•
•
Originally Posted by mr woo
I'm close, but can't see the error.......any idea's ??
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)
/* Program to read in a known number of data items and store them in an array */ var paymentArray = new Array (4); var total = new Number; 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 + Number(paymentArray[quarter]) total = parseFloat(total) } document.write('total amount paid is ' + total + '<br>')
You are definitely well on your way.
•
•
Join Date: Jan 2005
Posts: 6
Reputation:
Solved Threads: 0
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!
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!
![]() |
Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Javascript making image disappear?
- Next Thread: New Language combines: Asynchronous JavaScript+CSS+DOM+XMLHttpRequest
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug captchaformproblem checkbox close codes createrange() css cursor debugger decimal dependent disablefirebug dom download dropdown editor element engine error events explorer ext file firefox form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math media microsoft mp4 object onmouseoutdivproblem onreadystatechange paypal pdf php player position programming progressbar prototype redirect regex runtime safari scale scriptlets search security select size software sql text textarea unicode w3c window windowofwords windowsxp wysiwyg \n





