Showing posts with label Fahrenheit to celsius converter in javascript. Show all posts
Showing posts with label Fahrenheit to celsius converter in javascript. Show all posts

Sunday, December 11, 2016

Fahrenheit To Celsius Converter in JavaScript

Here is a sample program that I wrote in JavaScript that will ask the user to give temperature in Fahrenheit and then convert into Celsius equivalent.  The code is very simple and easy to understand.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output

Program Listing

<html>
<title> Fahrenheit To Celsius Converter 1.0
</title>
<body bgcolor="lightblue">
<font color="black" face="Arial" size="5">
<center>
<br>
 Fahrenheit To Celsius Converter 1.0
<br>
</center>
</font>
<style type="text/css">
.labelText {
 text-align : right;
 padding-right : 3px;
 color   : black;
 font-family:"Arial";
 font-size    : 18px;
}
</style>

 <form  name="temp" method="post">
<table>
<tr>
<tr>
 <td> &nbsp; </td>
 </tr>
<td class="labelText">  Enter Temperature in Fahrenheit

</td>
<td> <input type="text" name="fahr"  size="10"/> </td>
</tr>

 <tr>
 <td> &nbsp; </td>
 </tr>
</td>
<tr>
<td class="labelText">
The result is
</td>
<td> 
<input type="text" name="display"  size="50"/> </td>
 </tr>
  <tr>
 <td> &nbsp; </td>
 </tr>
</td>                   
<td> <input type="button" value="Compute" 
title="Click here to compute the temperature in celsius."
 onClick="compute1()">
</td> 
<td> <input type="button" value="Clear" 
title="Click here to clear the text box."
 onClick="clear_all()">
</td> 

</table>
</font>
</form>
<script language ="javascript">
function compute1()
{
var xval1, solve1,final_result;
var result;
  
value1 = parseInt(document.temp.fahr.value);
              
solve1 = 100/(212-32) * (value1 - 32 )
// For two decimal places convertion
 final_result = Math.round(solve1 * 100) /100;

result = value1 + " fahrenheit is equivalent to " 
               + final_result + " celsius. ";

document.temp.display.value = result;
}

function clear_all()
{
document.temp.fahr.value = "";
document.temp.display.value = "";
document.temp.fahr.focus(); 
}
</script>
</body>
</html>