Lekcja 1 Zadanie domowe 1

Kalkulator temperatury
JavaScript
Napisz program, który zamienia temperatury między Celsjuszem i Fahrenheitem. Program powinien zapytać użytkownika o wartość temperatury i jednostkę, a następnie przekonwertować i wyświetlić wynik w innej jednostce. Koncepty testowane: Wejście/wyjście, instrukcje warunkowe, funkcje, podstawowe operacje matematyczne
Wzór na konwersję: F = C * 9/5 + 32
Rozwiązanie zadania:
let temp = prompt("Please enter the temperature(Only numbers without spaces).");
let units = prompt("If the temperature is given in degrees Celsius, enter 1.
If it's in degrees Fahrenheit, enter 2 and press the OK button.");
let result = 0;
if (units == '1') {
result = (temp * 9 / 5) + 32;
units = 'Your temperature in degrees Fahrenheit is '
} else {
result = (temp - 32) * 5 / 9;
units = 'Your temperature in degrees Celsius is '
}
alert(units + result);