Created
January 2, 2020 06:31
-
-
Save 40823237/3c4149921d38005b3e0db7bd07ddead9 to your computer and use it in GitHub Desktop.
weight_change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "dart:html"; | |
LBtoKG(num lb){ | |
return lb*0.45359237; | |
} | |
KGtoLB(num kg){ | |
return kg*2.20462262; | |
} | |
main() { | |
InputElement tempInput = querySelector("#weight"); | |
querySelector("#submit").onClick.listen((e) => convert(tempInput.value)); | |
} | |
convert(String data){ | |
int len; | |
var type; | |
var number; | |
LabelElement output = querySelector("#output"); | |
len = data.length; | |
type = data[len-1]; | |
number = data.substring(0, len-1); | |
number = int.parse(number); | |
if (type == "L" || type == "l"){ | |
output.innerHtml = " $number 英磅 = ${LBtoKG(number).toStringAsFixed(2)} 公斤"; | |
} else if ((type == "K" || type == "k")){ | |
output.innerHtml = " $number 公斤 = ${KGtoLB(number).toStringAsFixed(2)} 英磅"; | |
} else { | |
output.innerHtml = "請輸入數字加上 L 或 K!"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment