Created
March 6, 2012 21:29
-
-
Save michaelaguiar/1989078 to your computer and use it in GitHub Desktop.
JS - Calculate BMI
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
| BMI Calculator |
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
| $(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); | |
| } |
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
| <!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