forked from wdi-sg/temperature_converter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2.js
More file actions
18 lines (17 loc) · 962 Bytes
/
script2.js
File metadata and controls
18 lines (17 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var temperature = prompt("What is the temperature?")
var temperatureUnit = prompt("What is the unit of the temperature? (fahrenheit, celsius or kelvin)")
if (temperatureUnit === "fahrenheit") {
var temperatureInCelsius = (temperature - 32) * (5/9);
var temperatureInKelvin = ((temperature - 32) * 5/9) + 273.15;
console.log(temperature + "\xB0F = " + temperatureInCelsius + "\xB0C = " + temperatureInKelvin + "K");
} else if (temperatureUnit === "celsius") {
var temperatureInFahr = (temperature * 9/5) + 32;
var temperatureInKelvin = temperature + 273.15;
console.log(temperature + "\xB0F = " + temperatureInCelsius + "\xB0C = " + temperatureInKelvin + "K");
} else if (temperatureUnit === "kelvin") {
var temperatureInFahr = ((temperature-273.15)*9/5)+32;
var temperatureInCelsius = temperature - 273.15;
console.log(temperature + "\xB0F = " + temperatureInCelsius + "\xB0C = " + temperatureInKelvin + "K");
} else {
console.log("Unit is invalid")
}