2014年10月26日 星期日

第六周


http://www.proglogic.com/code/javascript/calculator/bmi.php

作業找一個例子去改
有點難,改好竟然不能計算....哭

<!DOCTYPE html>
<html>
<head>
<title>From Action Example</title>
<meta name
<script language="JavaScript">
<!--
function calculateBmi() {
var weight = document.getElementById("weight").value;
var height = document.getElementById("height").value;
if(weight > 0 && height > 0){
var finalBmi = weight/(height/100*height/100)
document.getElementById.value = finalBmi
if(finalBmi < 18.5){
document.getElementById.value = "That you are too thin."
}
if(finalBmi > 18.5 && finalBmi < 25){
document.getElementById.value = "That you are healthy."
}
if(finalBmi > 25){
document.getElementById.value = "That you have overweight."
}
}
else{
alert("Please Fill in everything correctly")
}
}
//-->
<form name="id">
Your Weight(kg): <input type="text" name="weight" size="10"><br />
Your Height(cm): <input type="text" name="height" size="10"><br />
<input type="button" value="Calculate BMI" onClick="calculateBmi()"><br />
Your BMI: <input type="text" name="bmi" size="10"><br />
This Means: <input type="text" name="meaning" size="25"><br />
<input type="reset" value="Reset" />
</form>
</script>
</html>

沒有留言:

張貼留言