Trout69
06-27-2005, 11:16 PM
Now let me first start saying that i have read the posts that are located at http://www.codingforums.com/showthread.php?t=61565&highlight=celsius and am still stuck.
It seems that the code used to help out is in a slighly different format from that which we are using on the course, so no matter how much i stare at it i can't figure it out.
THE PROBLEM: The program runs fine, the debugger doesn't pick up any errors, but the output always remains at 0. I know this has to be something to do with it picking up the result as a string rather than a number, so i've tried to use parseFloat but to no avail. i have tried 2 locations in the code for this commenting out either/or to see if i can get it to work but i just can't.....i know its something very simple, but i don't get to cover debugging in great detail until my next unit so any help would be appreciated.
I have attached both the function libraries for this program, and the code is below - i have highlighted the two places i have tried parseFloat but left them commented out.
<script
language="JavaScript"
src="number_library.js"
type="text/javascript">
</script>
<script
language="JavaScript"
src="conversion_library.js"
type="text/javascript">
</script>
<script
language="JavaScript"
type="text/javascript">
//
// A FUNCTION THAT TAKES AN INPUT VALUE AND CONVERTS IT TO CELSIUS AFTER
// TESTING IF THE INPUT IS NUMERIC. THIS FUNCTION USES THE PRE-DEFINED
// LIBRARIES number_library.js AND conversion_library.js IF THE INPUT IS
// NOT NUMERIC AN ERROR MESSAGE IS SHOWN.
//
function fahrenheitToCelsius (fahrenheitTemp) {
var inputIsNotNumeric = false; // BOOLEAN VALUE - IS THE INPUT A NON-NUMERIC VALUE - INITIALISED TO FALSE
var celsiusTemp = 0.0; // THE OUTPUT VALUE - INITIALISED TO 0.0
//celsiusTemp = parseFloat(celsiusTemp);
//
// TEST THE INPUT VALUE TO SEE IF IT IS NON-NUMERIC OR NOT
//
inputIsNotNumeric = isNotNumeric (fahrenheitTemp);
//
// IF THE INPUT IS NUMERIC - PROCEED WITH CONVERSION TO CELSIUS
// AND DISPLAYING THE OUTPUT OTHERWISE PRODUCE AN ERROR MESSAGE
//
if (inputIsNotNumeric == false) {
celsiusTemp = roundToTwoPlaces(celsiusTemp);
//celsiusTemp = parseFloat (celsiusTemp);
window.alert("The temperature to two decimal places is " + celsiusTemp + ' degrees Celsius.');
}
else {
window.alert("Your input was not a number.");
}
}
</script>
If you would like the complete HTML document please let me know. Basically the GUI is a basic form with an input text box, a convert button and a reset button. you type the number, click convert and the output is displayed in a window alert.
I just really don't know, can't wait to get onto the debugging part of the course, will make my life easier.....
Thanks in advance
Trout
It seems that the code used to help out is in a slighly different format from that which we are using on the course, so no matter how much i stare at it i can't figure it out.
THE PROBLEM: The program runs fine, the debugger doesn't pick up any errors, but the output always remains at 0. I know this has to be something to do with it picking up the result as a string rather than a number, so i've tried to use parseFloat but to no avail. i have tried 2 locations in the code for this commenting out either/or to see if i can get it to work but i just can't.....i know its something very simple, but i don't get to cover debugging in great detail until my next unit so any help would be appreciated.
I have attached both the function libraries for this program, and the code is below - i have highlighted the two places i have tried parseFloat but left them commented out.
<script
language="JavaScript"
src="number_library.js"
type="text/javascript">
</script>
<script
language="JavaScript"
src="conversion_library.js"
type="text/javascript">
</script>
<script
language="JavaScript"
type="text/javascript">
//
// A FUNCTION THAT TAKES AN INPUT VALUE AND CONVERTS IT TO CELSIUS AFTER
// TESTING IF THE INPUT IS NUMERIC. THIS FUNCTION USES THE PRE-DEFINED
// LIBRARIES number_library.js AND conversion_library.js IF THE INPUT IS
// NOT NUMERIC AN ERROR MESSAGE IS SHOWN.
//
function fahrenheitToCelsius (fahrenheitTemp) {
var inputIsNotNumeric = false; // BOOLEAN VALUE - IS THE INPUT A NON-NUMERIC VALUE - INITIALISED TO FALSE
var celsiusTemp = 0.0; // THE OUTPUT VALUE - INITIALISED TO 0.0
//celsiusTemp = parseFloat(celsiusTemp);
//
// TEST THE INPUT VALUE TO SEE IF IT IS NON-NUMERIC OR NOT
//
inputIsNotNumeric = isNotNumeric (fahrenheitTemp);
//
// IF THE INPUT IS NUMERIC - PROCEED WITH CONVERSION TO CELSIUS
// AND DISPLAYING THE OUTPUT OTHERWISE PRODUCE AN ERROR MESSAGE
//
if (inputIsNotNumeric == false) {
celsiusTemp = roundToTwoPlaces(celsiusTemp);
//celsiusTemp = parseFloat (celsiusTemp);
window.alert("The temperature to two decimal places is " + celsiusTemp + ' degrees Celsius.');
}
else {
window.alert("Your input was not a number.");
}
}
</script>
If you would like the complete HTML document please let me know. Basically the GUI is a basic form with an input text box, a convert button and a reset button. you type the number, click convert and the output is displayed in a window alert.
I just really don't know, can't wait to get onto the debugging part of the course, will make my life easier.....
Thanks in advance
Trout