Mega Code Archive

 
Categories / JavaScript Tutorial / Function
 

Calculation in function

< html> <head> <title>A Simple Page</title> <script language="JavaScript"> <!-- function inputCels() {     var cels = 100;     ansFah = doFahCalc(cels);     alert(cels + " Degrees Celsius is " + ansFah + " Degrees Fahrenheit"); } function inputFah() {     var fah = 100;     ansCel = doCelCalc(fah);     alert(fah + " Degrees Fahrenheit is " + ansCel + " Degrees Celsius"); } function doCelCalc(fah) {     var ans = ((Number(fah) - 32) / 1.8);     return (ans); } function doFahCalc(cels) {     var ans = ((1.8 * Number(cels)) + 32);     return (ans); } //  --> </script> </head> <body> <input type="button" value="Convert Celsius to Fahrenheit" onClick="inputCels();"> <br> <input type="button" value="Convert Fahrenheit to Celsius" onClick="inputFah();"> </body> </html>