Created
July 2, 2015 14:31
-
-
Save gasolin/1037e54eb9bd43522196 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<h3>BMI</h3> | |
<label for="height">Height(cm)</label> | |
<input id="height"></input> | |
<br/> | |
<label for="weight">Weight(kg)</label> | |
<input id="weight"></input> | |
<br/> | |
<button id="calc">Submit</button> | |
<p id="report"></p> | |
<script> | |
var calc = document.getElementById('calc'); | |
var report = document.getElementById('report'); | |
var inputHeight = document.getElementById('height'); | |
var inputWeight = document.getElementById('weight'); | |
function calc_bmi() { | |
var height = parseFloat(inputHeight.value); | |
var weight = parseFloat(inputWeight.value); | |
var val = weight / (height * height / 10000); | |
return val.toFixed(2); | |
} | |
calc.addEventListener('click', function() { | |
report.innerHTML = calc_bmi(); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment