sivaramaiah  
 
  Record18 11/22/2017 3:42am (UTC)
   
 
Record 18: Converting between Units of Measurements

function convertTemperature(fMeasure, tMeasure, val)
{
fMeasure = fMeasure.toLowerCase( );
tMeasure = tMeasure.toLowerCase( );

if ( (fMeasure == "centigrade" || fMeasure == "celsius" || fMeasure == "c")
&& (tMeasure == "fahrenheit" || tMeasure == "f") )
{
return (val * 9/5) + 32;
}
else if ( (fMeasure == "fahrenheit" || fMeasure == "f") &&
(tMeasure == "centigrade" || tMeasure == "celsius" || tMeasure == "c") )
{
return (val - 32) * 5/9;
}
else
{
trace ("Invalid conversion type from " + fMeasure + " to " + tMeasure);
return NaN;
}
}trace("----------------------------------------------------------------------");
trace("converting 32 from centigrade to fahrenheit:"+convertTemperature("c","f",32));
trace("converting 64 from fahrenheit to centigrade:"+convertTemperature("f","c",64));
trace("----------------------------------------------------------------------");

function convertToCentigrade(fMeasure, val)
{
fMeasure = fMeasure.toLowerCase( );
if (fMeasure == "kelvin" || fMeasure == "k")
{
return (val - 273.15);
}
else if ( fMeasure == "fahrenheit" || fMeasure == "f" )
{
return (val - 32) * 5/9;
}
else if (fMeasure == "centigrade" || fMeasure == "celsius" || fMeasure == "c")
{
return val;
}
else
{
return NaN;
}
}
trace("----------------------------------------------------------------------");
trace("converting 78 from kelvin to centigrade:"+convertToCentigrade("k",78));
trace("converting 38 from fahrenheit to centigrade:"+convertToCentigrade("f",38));
trace("displaying the celsius value:"+convertToCentigrade("c",60));
trace("----------------------------------------------------------------------");

function convertFromCentigrade(tMeasure, val)
{
tMeasure = tMeasure.toLowerCase( );
if (tMeasure == "kelvin" || tMeasure == "k")
{
return (val + 273.15);
}
else if ( tMeasure == "fahrenheit" || tMeasure == "f" )
{
return (val * 9/5) + 32;
}
else if (tMeasure == "centigrade" || tMeasure == "celsius" || tMeasure == "c")
{
return val;
}
else
{
return NaN;
}
}
trace("----------------------------------------------------------------------");
trace("converting centigrade value 42 to kelvin:"+convertFromCentigrade("k",42));
trace("converting centigrade value 56 to farhenheit:"+convertFromCentigrade("f",56));
trace("displaying celsius value:"+convertFromCentigrade("c",72));
trace("----------------------------------------------------------------------");
/*function convertTemperature(fMeasure, tMeasure, val)
{
var centigradeVal = Math.convertToCentigrade (fMeasure, val);
return Math.convertFromCentigrade (tMeasure, centigradeVal );
}*/
function convertWeights(fMeasure, tMeasure, val)
{
if (fMeasure == "pounds" && tMeasure == "kilograms")
{
return val / 2.2;
}
else if (fMeasure == "kilograms" && tMeasure == "pounds")
{
return val * 2.2;
}
else
{
return "invalid conversion type";
}
}
trace("----------------------------------------------------------------------");
trace("converting 98 from pounds to kilograms:"+convertWeights("pounds","kilograms",98));
trace("converting 89 from kilograms to pounds:"+convertWeights("kilograms","pounds",89));
trace("----------------------------------------------------------------------");



-------------------------------------------------------------------------------------
output
 ----------------------------------------------------------------------
converting 32 from centigrade to fahrenheit:89.6
converting 64 from fahrenheit to centigrade:17.7777777777778
----------------------------------------------------------------------
----------------------------------------------------------------------
converting 78 from kelvin to centigrade:-195.15
converting 38 from fahrenheit to centigrade:3.33333333333333
displaying the celsius value:60
----------------------------------------------------------------------
----------------------------------------------------------------------
converting centigrade value 42 to kelvin:315.15
converting centigrade value 56 to farhenheit:132.8
displaying celsius value:72
----------------------------------------------------------------------
----------------------------------------------------------------------
converting 98 from pounds to kilograms:44.5454545454545
converting 89 from kilograms to pounds:195.8
----------------------------------------------------------------------
 
  Menu Items
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

  add
HOT TOPICS
MCA PROJECT DETAILS ------------------------------------- Jntu all Lab manuals ------------------------------------- Jntu Syllabus Books ------------------------------------- Paper presentations ------------------------------------- Seminars ------------------------------------- Campus Papers ------------------------------------- Competetive Exams GATE ------------------------------------- GRE ------------------------------------- TOEFL ------------------------------------- IELTS ------------------------------------- CAT ------------------------------------- GMAT ------------------------------------- Templates ------------------------------------- Students Resume Preparation tips ------------------------------------- Job zone(Interview questions) ------------------------------------- Google Adsence html code ------------------------------------- Web sites --------x--------------x-----------
  Advertisement
  Advertisement

 


-----------------------------
  Offline Messages
  Adds
  Visitors Information
Today, there have been 67422 visitors (190490 hits) on this page!
=> Do you also want a homepage for free? Then click here! <= --------------------------------------------------