Skip to content

Instantly share code, notes, and snippets.

@sahidursuman
Forked from michaelaguiar/README
Created November 23, 2018 17:52
Show Gist options
  • Select an option

  • Save sahidursuman/a44a04631e7414b60ec3fd179c56bb4e to your computer and use it in GitHub Desktop.

Select an option

Save sahidursuman/a44a04631e7414b60ec3fd179c56bb4e to your computer and use it in GitHub Desktop.
JS - Calculate BMI
BMI Calculator
$(document).ready(function() {
$('#frmBMI').submit(function(e) {
e.preventDefault();
var heightFt = $('input[name="height_ft"]').val(),
heightIn = $('input[name="height_in"]').val(),
height = parseFloat(heightFt * 12) + parseFloat(heightIn);
weight = $('input[name="weight"]').val(),
BMI = calculateBMI(height, weight);
$('#response').text('Your BMI is '+BMI);
});
});
function calculateBMI(height, weight) {
var BMI = (weight / (height * height)) * 703
return Math.round(BMI * Math.pow(10, 2)) / Math.pow(10, 2);
}
<!DOCTYPE html>
<html>
<head>
<title>BMI Calculator</title>
<meta charset="UTF-8">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="core.js"></script>
</head>
<body>
<form id="frmBMI">
<div>
<label>Height:</label>
<input type="text" name="height_ft" /> ft
<input type="text" name="height_in" /> in
</div>
<div>
<label>Weight:</label>
<input type="text" name="weight" /> lbs
</div>
<input type="submit" value="Submit" />
</form>
<div id="response"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment