viewing paste convert | Javascript

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
var convert = function (strInput) {
    strInput = strInput.toLowerCase();
   
    var amount = parseFloat(strInput, 10);
    var strAmount = strInput.replace(amount, "").trim();
 
    switch (strAmount) {
        case "pounds":
        case "pounds":
        case "lb":
        case "lbs":
            return amount * 0.454 + " kg";
        case "miles":
        case "mile":
            return amount * 1.61 + " km";
        default:
            return undefined;
    }
 
};
Viewed 1508 times, submitted by Streusel.