Skip to content

Instantly share code, notes, and snippets.

@gasolin
Created July 2, 2015 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gasolin/1037e54eb9bd43522196 to your computer and use it in GitHub Desktop.
Save gasolin/1037e54eb9bd43522196 to your computer and use it in GitHub Desktop.
<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