forked from wdi-sg/temperature_converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
75 lines (67 loc) · 2.03 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
console.log("hello script js");
var tempC = null;
var tempF = null;
var tempK = null;
var inputHappened = function(currentInput, currentUnit, currentName){
console.log( currentInput, currentUnit);
if(currentUnit == "fahrenheit"){
tempC = fahrenheitCelcius(currentInput);
tempK = fahrenheitKelvin(currentInput);
tempF = currentInput;
}
else if(currentUnit == "celcius"){
tempC = currentInput;
tempK = celciusKelvin(currentInput);
tempF = celciusFahrenheit(currentInput);
}
else if(currentUnit == "kelvin"){
tempC = kelvinCelcius(currentInput);
tempK = currentInput;
tempF = kelvinFahrenheit(currentInput);
}
var output = tempC + "C " + tempK + "K " + tempF + "F ";
if(tempC >= 100){
output = output + "-- Don't go outside if you want to live";//"-- You are literally boiling!";
}
else if(tempC > 28){
if(tempC >= 40){
output = output + "-- ooh it's hot out there.. might be a goodtime for a swim!";
}
else{
output = output + "-- ooh it's hot out there.. wear some shorts and a shirt!";
}
}
else if(tempC <= 20){
if(tempC < 0){
output = output + "-- ooh it's freezing.. might want to grab a heavy jacket";
}
else{
output = output + "-- ooh it's really cold out there.. bring a sweater and a jacket!";
}
}
return "Hello " + currentName + ", " + output;
};
var fahrenheitCelcius = function(inputTemp){
var celcOut = (5/9) * (inputTemp - 32);
return celcOut;
}
var fahrenheitKelvin = function(inputTemp){
var kelvOut = (5/9) * (inputTemp - 32) + 273;
return kelvOut;
}
var celciusFahrenheit = function(inputTemp){
var fahrOut = (9/5) * inputTemp + 32;
return fahrOut;
}
var celciusKelvin = function(inputTemp){
var kelvOut = inputTemp + 273;
return kelvOut;
}
var kelvinFahrenheit = function(inputTemp){
var fahrOut = (9/5) * (inputTemp - 273) + 32;
return fahrOut;
}
var kelvinCelcius = function(inputTemp){
var celcOut = inputTemp - 273;
return celcOut;
}