SHARE
TWEET

Untitled

a guest Oct 15th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ConvertCtoF(degreesCelsius){
  2.     var Fah = (degreesCelsius * (9/5)) + 32;
  3.     return Fah;
  4. }
  5.  
  6. function ConvertFtoC(degreesFahrenheit){
  7.     var Cel = (degreesFahrenheit - 32) * (5 / 9);
  8.     return Cel;
  9. }
  10.  
  11. function bodyLoaded() {
  12.     var button = document.getElementById('ConvertButton');
  13.     var C = document.getElementById('CInput');
  14.     var F = document.getElementById('FInput');
  15.     var err = document.getElementById('ErrDiv');
  16.     var weather = document.getElementById('WeatherImage');
  17.     button.addEventListener('click', function() {
  18.         if (C.value != "") {
  19.                 if (isNaN(parseFloat(C.value))) {
  20.                     err.innerHTML = C.value + " is not a number";
  21.                 } else {
  22.                     F.value = ConvertCtoF(parseFloat(C.value));
  23.                     err.innerText = "";
  24.                 }
  25.         }else if (F.value != "") {
  26.             if (isNaN(parseFloat(F.value))) {
  27.                 err.innerText = F.value + " is not a number";
  28.             } else {
  29.                 C.value = ConvertFtoC(parseFloat(F.value));
  30.                 err.innerText = "";
  31.             }
  32.         }
  33.         if(F.value < 32){
  34.             weather.src = "cold.gif";
  35.         }else if (F.value <= 50){
  36.             weather.src = "cool.gif";
  37.         }else {
  38.             weather.src = "warm.gif";
  39.         }
  40.     })
  41.     C.addEventListener('input', function(){
  42.         if (F.value != ""){
  43.             F.value = "";
  44.         }
  45.     });
  46.     F.addEventListener('input', function(){
  47.         if (C.value != ""){
  48.             C.value = "";
  49.         }
  50.     } );
  51. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top