12345678910111213141516171819202122 |
- <header>
- <h1>Temperature</h1>
- </header>
- <body>
- <script>
- const tempConvert = (value, isCelsius) =>
- isCelsius ? (temperVal - 32.0) * 5.0 / 9.0 : (temperVal * 9.0 / 5.0) + 32.0;
- let temperStr = prompt("Enter please temperature with F or C ");
- temperVal = temperStr.substring(0, temperStr.length - 1);
- if (temperStr.charAt(temperStr.length - 1) == 'F') {
- let temperCels = tempConvert(temperVal, true);
- alert("Temperature in Celsius: " + temperCels.toFixed(1) + "C");
- }
- else {
- let temperFahr = tempConvert(temperVal, false);
- alert("Temperature in Fahrengeit: " + temperFahr.toFixed(1) + "F");
- }
- </script>
- </body>
|