Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  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. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement