Add support for weight conversion
KG => LB LB => KG
This commit is contained in:
parent
b724a51868
commit
af058d876a
1 changed files with 32 additions and 5 deletions
|
@ -14,32 +14,59 @@ module.exports = {
|
||||||
args[2] = args[3];
|
args[2] = args[3];
|
||||||
}
|
}
|
||||||
let sendText = "";
|
let sendText = "";
|
||||||
let initial_temp = parseFloat(args[0])
|
let initial_number = parseFloat(args[0])
|
||||||
switch (args[1].toUpperCase()) {
|
switch (args[1].toUpperCase()) {
|
||||||
case "C":
|
case "C":
|
||||||
if (args[2].toUpperCase() === "F") {
|
if (args[2].toUpperCase() === "F") {
|
||||||
let fahrenheit = ((initial_temp * 9 / 5) + 32).toFixed(2);
|
let fahrenheit = ((initial_number * 9 / 5) + 32).toFixed(2);
|
||||||
if(fahrenheit[fahrenheit.length - 1] === '0' && fahrenheit[fahrenheit.length - 2] === "0"){
|
if(fahrenheit[fahrenheit.length - 1] === '0' && fahrenheit[fahrenheit.length - 2] === "0"){
|
||||||
fahrenheit = fahrenheit.replace(".00","")
|
fahrenheit = fahrenheit.replace(".00","")
|
||||||
}
|
}
|
||||||
|
|
||||||
sendText = `${initial_temp}°C is ${fahrenheit}°F`;
|
sendText = `${initial_number}°C is ${fahrenheit}°F`;
|
||||||
} else {
|
} else {
|
||||||
sendText = "Can only convert to celsius from fahrenheit";
|
sendText = "Can only convert to celsius from fahrenheit";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "F":
|
case "F":
|
||||||
if (args[2].toUpperCase() === "C") {
|
if (args[2].toUpperCase() === "C") {
|
||||||
let celsius = ((initial_temp - 32) * 5 / 9).toFixed(2);
|
let celsius = ((initial_number - 32) * 5 / 9).toFixed(2);
|
||||||
if(celsius[celsius.length - 1] === '0' && celsius[celsius.length - 2] === "0"){
|
if(celsius[celsius.length - 1] === '0' && celsius[celsius.length - 2] === "0"){
|
||||||
celsius = celsius.replace(".00","")
|
celsius = celsius.replace(".00","")
|
||||||
}
|
}
|
||||||
|
|
||||||
sendText = `${initial_temp}°F is ${celsius}°C`;
|
sendText = `${initial_number}°F is ${celsius}°C`;
|
||||||
} else {
|
} else {
|
||||||
sendText = "Can only convert to fahrenheit from celsius";
|
sendText = "Can only convert to fahrenheit from celsius";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "KG":
|
||||||
|
if (args[2].toUpperCase() === "LB" || args[2].toUpperCase() === "LBS") {
|
||||||
|
let LB = (initial_number * 2.20462262).toFixed(2);
|
||||||
|
|
||||||
|
if(LB[LB.length - 1] === '0' && LB[LB.length - 2] === "0"){
|
||||||
|
LB = LB.replace(".00","")
|
||||||
|
}
|
||||||
|
|
||||||
|
sendText = `${initial_number} kg is ${LB} lb`;
|
||||||
|
} else {
|
||||||
|
sendText = "Can only convert to lb from kg.";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "LB":
|
||||||
|
case "LBS":
|
||||||
|
if (args[2].toUpperCase() === "KG") {
|
||||||
|
let KG = (initial_number / 2.20462262).toFixed(2);
|
||||||
|
|
||||||
|
if(KG[KG.length - 1] === '0' && KG[KG.length - 2] === "0"){
|
||||||
|
KG = KG.replace(".00","")
|
||||||
|
}
|
||||||
|
|
||||||
|
sendText = `${initial_number} lb is ${KG} kg`;
|
||||||
|
} else {
|
||||||
|
sendText = "Can only convert to kg from lb.";
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
sendText = "No conversion method for that yet"
|
sendText = "No conversion method for that yet"
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue