473,769 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Temperature Converter

25 New Member
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_tem p - 32) * .55
The only tip/clue I have is to use
var tempInCelcius = (document.Conve rter.fahrenheit .value - 32) * .55;
var tempInFahrenhei t = (document.Conve rter.celcius.va lue * 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!

<html>
<head>
<title>Conver t Temperature</title>

<script language="JavaS cript">

<!--Hide from old browsers
function tempConv() {
var TempInCelcius = document.Conver ter.fahrenheit. value - 32) * .55;
var TempInFahrenhei t = document.Conver ter.celcius.val ue * 1.8) + 32;

?????? - I cannot get the calc right????????


//-->
</script>

</head>
<body>

<h1>Convert Temperature</h1>
<form name=data>
<p><strong>Ente r the temperature in Fahrenheit</strong></p>
<input type="text" name="Celcius" size="10" align="left">
<input type="Button" align="left" value="Convert to Celcius" onClick=tempCon v()>
<br>
<p><strong>Ente r the temperature in Celcius</strong></p>
<input type="text" name="fahrenhei t_in" size="10" align="left">
<input type="Button" align="left" value="Convert to Fahrenheit" onClick="tempCo nv()">


</body>
</html>
Jun 16 '07 #1
16 4428
jsakalos
12 New Member
Use Math object. It has round, floor and maybe other methods you can use.
Jun 16 '07 #2
improvcornartist
303 Recognized Expert Contributor
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
  1. <html>
  2. <head>
  3. <title>Convert Temperature</title>
  4.  
  5. <script language="JavaScript">
  6.  
  7. <!--Hide from old browsers
  8. function tempConv() {
  9. var TempInCelcius = (document.Converter.fahrenheit_in.value - 32) * .55;
  10. var TempInFahrenheit = (document.Converter.celcius.value * 1.8) + 32;
  11.  
  12. alert(TempInCelcius);
  13. alert(TempInFahrenheit);
  14. }
  15. //-->
  16. </script>
  17.  
  18. </head>
  19. <body>
  20.  
  21. <h1>Convert Temperature</h1>
  22. <form name="Converter">
  23. <p><strong>Enter the temperature in Fahrenheit</strong></p>
  24. <input type="text" name="celcius" size="10" align="left">
  25. <input type="Button" align="left" value="Convert to Celcius" onClick="tempConv();">
  26. <br>
  27. <p><strong>Enter the temperature in Celcius</strong></p>
  28. <input type="text" name="fahrenheit_in" size="10" align="left">
  29. <input type="Button" align="left" value="Convert to Fahrenheit" onClick="tempConv();">
  30.  
  31. </form>
  32. </body>
  33. </html>
Jun 17 '07 #3
Brigitte Behrmann
25 New Member
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
  1. <html>
  2. <head>
  3. <title>Convert Temperature</title>
  4.  
  5. <script language="JavaScript">
  6.  
  7. <!--Hide from old browsers
  8. function tempConv() {
  9. var TempInCelcius = (document.Converter.fahrenheit_in.value - 32) * .55;
  10. var TempInFahrenheit = (document.Converter.celcius.value * 1.8) + 32;
  11.  
  12. alert(TempInCelcius);
  13. alert(TempInFahrenheit);
  14. }
  15. //-->
  16. </script>
  17.  
  18. </head>
  19. <body>
  20.  
  21. <h1>Convert Temperature</h1>
  22. <form name="Converter">
  23. <p><strong>Enter the temperature in Fahrenheit</strong></p>
  24. <input type="text" name="celcius" size="10" align="left">
  25. <input type="Button" align="left" value="Convert to Celcius" onClick="tempConv();">
  26. <br>
  27. <p><strong>Enter the temperature in Celcius</strong></p>
  28. <input type="text" name="fahrenheit_in" size="10" align="left">
  29. <input type="Button" align="left" value="Convert to Fahrenheit" onClick="tempConv();">
  30.  
  31. </form>
  32. </body>
  33. </html>
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
  1. <html>
  2. <head>
  3. <title>Convert Temperature</title>
  4.  
  5. <script language="JavaScript">
  6.  
  7. <!--Hide from old browsers
  8.    function tempConv() {
  9.         var TempInCelcius = (document.Converter.fahrenheit_in.value - 32) * 0.55;
  10.         var TempInFahrenheit = (document.Converter.celcius_in.value * 1.8) + 32;
  11.         window.alert("The temperature you entered as Fahrenheit is equal to " + TempInCelcius + " in Celcius");
  12.         window.alert("The temperature you entered as Celcius is equal to " + TempInFahrenheit + " in Fahrenheit");
  13. }
  14.  
  15. //-->
  16. </script>
  17.  
  18. </head>
  19. <body>
  20.  
  21. <h1>Convert Temperature</h1>
  22. <form name="Converter">
  23. <p><strong>Enter the temperature in Fahrenheit</strong></p>
  24. <input type="text" name="celcius_in" size="10" align="left">
  25. <input type="Button" align="left" value="Convert to Celcius" onClick="tempConv();">
  26. <br>
  27. <p><strong>Enter the temperature in Celcius</strong></p>
  28. <input type="text" name="fahrenheit_in" size="10" align="left">
  29. <input type="Button" align="left" value="Convert to Fahrenheit" onClick="tempConv();">
  30.  
  31. </form>
  32. </body>
  33. </html>
  34.  
Jun 17 '07 #4
gits
5,390 Recognized Expert Moderator Expert
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
gits
5,390 Recognized Expert Moderator Expert
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
  1. // when calling the function pass param to it
  2.  
  3. function(param) {
  4.     if (params == 'whatever') {
  5.         // do this
  6.     } else {
  7.         // do that
  8.     }
  9. }
  10.  
kind regards
Jun 17 '07 #6
gits
5,390 Recognized Expert Moderator Expert
;) note the typo in the above example : params has to be param in the condition ... sorry ;))
Jun 17 '07 #7
Brigitte Behrmann
25 New Member
;) 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_tem p – 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.400000000000 006. 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
gits
5,390 Recognized Expert Moderator Expert
;) 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
Brigitte Behrmann
25 New Member
;) 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
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html>
  4. <head>
  5. <title>Convert Temperature</title>
  6.  
  7. <script language="JavaScript">
  8.  
  9. <!--Hide from old browsers
  10.    function tempConv() {
  11.         var TempInCelcius = (document.Converter.fahrenheit_in.value - 32) * 0.55;
  12.         var TempInFahrenheit = (document.Converter.celcius_in.value * 1.8) + 32;
  13.         window.alert("The temperature you entered as Fahrenheit is equal to " + TempInCelcius + " in Celcius");
  14.         window.alert("The temperature you entered as Celcius is equal to " + TempInFahrenheit + " in Fahrenheit");
  15. }
  16.  
  17. //-->
  18. </script>
  19.  
  20. </head>
  21. <body>
  22.  
  23. <h1>Convert Temperature</h1>
  24. <form name="Converter">
  25.  
  26. <p><strong>Enter the temperature in Fahrenheit</strong></p>
  27. <input type="text" name="fahrenheit_in" size="10" align="left">
  28. <input type="Button" align="left" value="Convert to Fahrenheit" onClick="tempConv();">
  29. <br><p><strong>Enter the temperature in Celcius</strong></p>
  30. <input type="text" name="celcius_in" size="10" align="left">
  31. <input type="Button" align="left" value="Convert to Celcius" onClick="tempConv();">
  32.  
  33. </form>
  34. </body>
  35. </html>
Jun 17 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
7848
by: Derek Ross | last post by:
Hello, Say I have a server that's saving the CPU temperature to 'temperature.js' once a second. The contents of the file is one single line: var temperature = "35.5"; And it changes as the temperature changes.
52
9674
by: piaseckiac | last post by:
I am producing a website on air and need a link to change the entire website from standard to metric for temperature, pressure, miles-kilometers, and volume. Thank you.
1
12134
by: deanfamily11 | last post by:
I'm trying to have this program do a simple temperature conversion from Fahrenheit to Celsius. I have confirmed that the other variable is receiving and calculating the conversion, but it is just outputting as "0". Any thoughts? (Code is below) #include <iostream> #include <iomanip> using namespace std;
1
1781
by: sjaak | last post by:
Hi, Im just starting out with C#, I try to make a console application where the user has to fill in temperature in celsius degrees and gets fahrenheit, my code sucks ; can anyone help me out with this ? this is my code.. using System; namespace ConsoleApplication1 {
5
32498
by: anthony | last post by:
One the computer I am programmig I could see the CPU temperature in the BIOS, is there a system DLL in VB.NET that I can call to display the temperature in my software? Thanks!
1
3200
by: pollardw | last post by:
i have written a small program to convert Fahrenheit to Celsius and I have a minor problem. Here is the code what do i need to change to get it to work? /* Convert Fahrenheit to Celsius */ #include <iostream> #include <iomanip> #include <string>
25
4903
by: kid joe | last post by:
Hi, Is it normal for the temperature of your CPU to increase as time goes on? I've got an Athlon XP 2100+ and I see that the temp is now at 51C where it used to be around 42 to 44. Anyone have any ideas?
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.