459,747 Members | 1,808 Online
Need help? Post your question and get tips & solutions from a community of 459,747 IT Pros & Developers. It's quick & easy.

# Temperature Converter

 P: 25 I am absolutely stuck with this one. I have to create a temperature conversion calculator that rounds the resulting temperature to the nearest whole number & vice versa. The result must be displayed in a window alert. The given formula is (Fahrenheit_temp - 32) * .55 The only tip/clue I have is to use var tempInCelcius = (document.Converter.fahrenheit.value - 32) * .55; var tempInFahrenheit = (document.Converter.celcius.value * 1.8) + 32 I have tried, deleted, tried and deleted again. I am so frustrated and feeling suicidal that I am just not grasping the concept. PLEASE HELP! Convert Temperature

Convert Temperature

Enter the temperature in Fahrenheit

Enter the temperature in Celcius

Jun 16 '07 #1
16 Replies

 P: 12 Use Math object. It has round, floor and maybe other methods you can use. Jun 16 '07 #2

 Expert 100+ P: 303 You had a few syntax errors. Look at the following code for some corrections. If you have more questions while finishing your project, I'll be glad to help. Expand|Select|Wrap|Line Numbers Convert Temperature

Convert Temperature

Enter the temperature in Fahrenheit

Enter the temperature in Celcius

Jun 17 '07 #3

 P: 25 You had a few syntax errors. Look at the following code for some corrections. If you have more questions while finishing your project, I'll be glad to help. Expand|Select|Wrap|Line Numbers Convert Temperature

Convert Temperature

Enter the temperature in Fahrenheit

Enter the temperature in Celcius

I have made some changes but I still have the following problems: 1. If I enter 100 in the fahrenheit box and convert to celcius I get a temperature altert of -17.6 but it should return a value of 37.4 2. It does the function twice on click as I have not separated the entry values into either or.... don't know how! 3. I also need to round the returned numbers off to not include decimal points. Expand|Select|Wrap|Line Numbers Convert Temperature

Convert Temperature

Enter the temperature in Fahrenheit

Enter the temperature in Celcius

Jun 17 '07 #4

 Expert Mod 5K+ P: 5,390 hi ... have a look at your input-fields ... that have the wrong order! correct it and it should work. I've seen that you know how to round a floating number ... so you should be able to solve this problem ... kind regards ... Jun 17 '07 #5

 Expert Mod 5K+ P: 5,390 and your problem nr. 2. - you should pass the value of your input-field or at least a param to differ between the buttons within your function ... so that you process only one conversion dependent to your input-parameter ... i give you an example: Expand|Select|Wrap|Line Numbers // when calling the function pass param to it   function(param) {     if (params == 'whatever') {         // do this     } else {         // do that     } }   kind regards Jun 17 '07 #6

 Expert Mod 5K+ P: 5,390 ;) note the typo in the above example : params has to be param in the condition ... sorry ;)) Jun 17 '07 #7

 P: 25 ;) note the typo in the above example : params has to be param in the condition ... sorry ;)) Okay you have lost me again!!!! Doesn't take much as you may have noticed! Here is the question, please help me from beginning to end, I just have no idea where what goes! Question 2 = 15 marks You convert a Fahrenheit temperature to Celsius using the following formula: (Fahrenheit_temp – 32) * .55. The result returned from a formula such as this often results in a number with decimal places. However, you usually display a temperature rounded to the nearest whole number. For example, when you convert the Fahrenheit temperature of 100 degrees to Celsius, the result is 47.400000000000006. Create a temperature conversion calculator that rounds the resulting temperatures to the nearest whole number and vice versa. See example below. CONVERT TEMPERATURE Enter the temperature in Fahrenheit: (text box) (Button: Convert to Celcius) Enter the temperature in Celcius: (text box) (Button: Convert to Fahrenheit) Jun 17 '07 #8

 Expert Mod 5K+ P: 5,390 ;) first have a look at your html form. you enter 'celsius_in' but you want 'fahrenheit_in' at this point ... right? switch it ... at first ... have a look at the result ... it should be ok then? Jun 17 '07 #9

 P: 25 ;) first have a look at your html form. you enter 'celsius_in' but you want 'fahrenheit_in' at this point ... right? switch it ... at first ... have a look at the result ... it should be ok then? Okay, did that but I still get two responses. Gives me the temp in the window alert, click OK and then I get the 2nd alert! Where does the param code you suggested fit in with what I got: Expand|Select|Wrap|Line Numbers Convert Temperature

Convert Temperature

Enter the temperature in Fahrenheit

Enter the temperature in Celcius

Jun 17 '07 #10

 Expert Mod 5K+ P: 5,390 ... ;) ok ... next step: onclick of your button you call the function tempConv(); ... right? call it at your first button with a simple string as param lets say: 'fahrenheit_conversion' so it looks like: Expand|Select|Wrap|Line Numbers onclick="tempConv('fahrenheit_conversion');" the second call gets 'celsius_conversion' ok? so within the function now you may adapt the example from above ... create an if-statement that makes the conversion from fahrenheit to celsius when param is 'fahrenheit_conversion' and the other conversion when it gets 'celsius_conversion' ... ok? try it ... please ;) kind regards ... Jun 17 '07 #11

 P: 25 ... ;) ok ... next step: onclick of your button you call the function tempConv(); ... right? call it at your first button with a simple string as param lets say: 'fahrenheit_conversion' so it looks like: Expand|Select|Wrap|Line Numbers onclick="tempConv('fahrenheit_conversion');" the second call gets 'celsius_conversion' ok? so within the function now you may adapt the example from above ... create an if-statement that makes the conversion from fahrenheit to celsius when param is 'fahrenheit_conversion' and the other conversion when it gets 'celsius_conversion' ... ok? try it ... please ;) kind regards ... I understand you really are trying to get me to help myself, but please understand that after only one week of self help with a text book, I really have no idea what I am doing. I still have it all wrong: I think I should just give it up and submit an incorrect assignment and hope that by the end of the year I have learnt enough to pass the exam. Expand|Select|Wrap|Line Numbers Convert Temperature

Convert Temperature

Enter the temperature in Fahrenheit

Enter the temperature in Celcius

Jun 17 '07 #12

 Expert Mod 5K+ P: 5,390 ;) you nearly have it ... replace the script area with the following: Expand|Select|Wrap|Line Numbers     that will do the job ... don't give up !! ... ;) kind regards Jun 17 '07 #13

 P: 25 ;) you nearly have it ... replace the script area with the following: Expand|Select|Wrap|Line Numbers     that will do the job ... don't give up !! ... ;) kind regards Thank you sooooooooo much. Last question, how do I now round the resulting temperature. I presume I use Math.round but do not know how this fits in. Kind regards, BB Jun 17 '07 #14

 Expert Mod 5K+ P: 5,390 hey ;)) ... ok last step - after the line: Expand|Select|Wrap|Line Numbers var TempInCelcius = (document.Converter.fahrenheit_in.value - 32) * 0.55;   you put ... that rounds the value: Expand|Select|Wrap|Line Numbers TempInCelcius = Math.round(TempInCelcius);   some lines later you do the same for TempInFahrenheit ... all right? :) kind regrads Jun 17 '07 #15

 P: 25 hey ;)) ... ok last step - after the line: Expand|Select|Wrap|Line Numbers var TempInCelcius = (document.Converter.fahrenheit_in.value - 32) * 0.55;   you put ... that rounds the value: Expand|Select|Wrap|Line Numbers TempInCelcius = Math.round(TempInCelcius);   some lines later you do the same for TempInFahrenheit ... all right? :) kind regrads Thanks so much, I see what I did wrong: I entered Expand|Select|Wrap|Line Numbers  var TempInCelcius=Math.round(TempInCelcius); instead of TempInCelcius=Math.round(TempInCelcius); If you are not too busy can you have a look at a post called Phone Number that I have just submitted.... Cheerio BB Jun 17 '07 #16

 P: 1 Hey BB! Your questions have helped me so much, you the bomb! Where are you from? Jun 23 '07 #17