Ejemplo switch case Calculando Grados Fahrenheit Celsius y Kelvin Javascript


En este ejemplo echo en javascript utilizaremos Las Formulas de conversión de incrementos
de grados Fahrenheit Celsius y Kelvin para calcular el valor de temperatura Introducido utilizando el switch del cual ejecutaremos x acción dependiendo del valor que se aya elegido en el combobox html con el id acción.



Formulas:
Fahrenheit a Celsius   C =(F-32)*5/9
Fahrenheit a Kelvin K = (F-32)*5/9 +273

Celsius a Fahrenheit  F =C*9/5+32
Celsius a Kelvin K=C+273

Kelvin a Fahrenheit   F= (k-273)9/5+32
Kelvin a Celsius C=K-273

Código:

<html> 
  <head> 
  <title>Conversiones</title> 
  </head> 
  <body>
  <script type="text/javascript">
  var C,K,F;
  function reseT()
  {
  C=0;K=0;F=0;
  }
  function Calcular()
{          
  var opcion = document.getElementById("accion").value;
  if(opcion != '')
                  { 








Kelvin a Celsius C=K-273
*/

 
        switch (opcion)
           {     //Fahrenheit a Celsius   C =(F-32)*5/9
                  case 'Fahrenheit a Celsius':
                    F = document.getElementById("num").value
       C =(F-32)*5/9;
       alert(" C: " + C +"");
       reseT();
       break;
     //Fahrenheit a Kelvin K = (F-32)*5/9 +273
      case 'Fahrenheit a Kelvin':
                     F = document.getElementById("num").value
        K = (F-32)*5/9 +273;
                     alert(" K: " + K);
      reseT();
      break;
      //Celsius a Fahrenheit  F =C*9/5+32
      case 'Celsius a Fahrenheit':
                     C = document.getElementById("num").value
        F =C*9/5+32;
     alert(" " + F +" F");
     reseT();
     break;
     //Celsius a Kelvin K=C+273
      case 'Celsius a Kelvin':
                     C = document.getElementById("num").value;
        K=C+273;
      alert(" K: " + K );
      reseT();
                   break;
      //Kelvin a Fahrenheit   F= (k-273)9/5+32
      case 'Kelvin a Fahrenheit':
                     K = document.getElementById("num").value;
        F= (K-273)*9/5+32;
      alert(" F: " + F );
      reseT();
                   break;
       //Kelvin a Celsius C=K-273
      case 'Kelvin a Celsius':
                     K = document.getElementById("num").value;
        C=K-273;
      alert(" C: " + C );
      reseT();
                   break;
       
       }
  
  } else {alert("Error");}
  
}
  </script>
  
  Calculando Grados Fahrenheit Javascript
<form action="#" method="post"> 
  Seleccione la conversion que quiere haser: 
   <p>accion<br>
<select id = "accion" name="accionok">
<option  value="Fahrenheit a Celsius">Fahrenheit a Celsius</option>
<option  value="Fahrenheit a Kelvin">Fahrenheit a Kelvin </option>
<option  value="Celsius a Fahrenheit">Celsius a Fahrenheit</option>
<option  value="Celsius a Kelvin">Celsius a Kelvin</option>
<option  value="Kelvin a Fahrenheit">Kelvin a Fahrenheit</option>
<option  value="Kelvin a Celsius">Kelvin a Celsius</option>
</select></p>
  <br>Ingrese valor a convertir<br>
  <input type="text"  id ="num" name="numero">
  <br>    
<input type="button" onClick="Calcular()" value="Calcular">
  </form>

  
  </body> 
</html>



Ejecutar Ejemplo:

                                                                 Descargar Ejemplo

Comentarios

Populares

Buscar en este blog