hw08_01_!Temperature.html 738 B

12345678910111213141516171819202122
  1. <header>
  2. <h1>Temperature</h1>
  3. </header>
  4. <body>
  5. <script>
  6. const tempConvert = (value, isCelsius) =>
  7. isCelsius ? (temperVal - 32.0) * 5.0 / 9.0 : (temperVal * 9.0 / 5.0) + 32.0;
  8. let temperStr = prompt("Enter please temperature with F or C ");
  9. temperVal = temperStr.substring(0, temperStr.length - 1);
  10. if (temperStr.charAt(temperStr.length - 1) == 'F') {
  11. let temperCels = tempConvert(temperVal, true);
  12. alert("Temperature in Celsius: " + temperCels.toFixed(1) + "C");
  13. }
  14. else {
  15. let temperFahr = tempConvert(temperVal, false);
  16. alert("Temperature in Fahrengeit: " + temperFahr.toFixed(1) + "F");
  17. }
  18. </script>
  19. </body>