-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunitConverters
34 lines (31 loc) · 885 Bytes
/
unitConverters
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
//functions to convert various units from standard to metric and so on
//Farenheit to Celsius equations fixed
//TODO: Unit testing and debugging
function tempConvert(temp, unit, target){
if (unit == "celsius"){
if (target == "kelvin"){
temp = temp - 273.15;
return temp;
} else if (target == "farenheit"){
temp = (9/5) * temp + 32;
return temp;
}
} else if (unit == "kelvin"){
if (target == "celsius"){
temp = temp + 273.15;
return temp;
} else if (target == "farenheit"){
temp = ((temp + 273.15)*(9/5))+32;
return temp;
}
} else if (unit == "farenheit"){
if (target == "celsius"){
temp = (5/9) * (temp-32);
return temp;
} else if (target == "kelvin"){
temp = ((5/9) * (temp-32)) - 273.15;
return temp;
}
}
}
console.log(tempConvert(-173.15, "kelvin", "farenheit"))